Are you sure? I thought IBM was talking to Gary Kildall at the same time they were talking to Gates. Supposedly, they showed up at his house, Kildall was out, his wife wouldn’t sign an NDA, so Gates ended up getting first crack, and the rest is history.
I think that is true (in regards to Kildall), but what I posted is also true - Gates/Microsoft did not initially write MSDOS (intially known as PC-DOS). He bought it. See this article