Moffat has been a fan of Doctor Who and Sherlock Holmes since before he could reverse his own polarity, and has often used his own life experiences as inspiration. His divorce, social life and career as a teacher have all served towards his creativity in the past, so he's obviously not just making stuff up as he goes along - he's proved that this broad experience of social interaction has made its way into his work, creating more realism than maybe a lot of us who haven't 'been there' realize.
Also, he's been a proud Whovian since childhood, so he's had these ideas for a while. If anybody knows the show, it's the people who were there when it was all going down, and Moffat is definitely one of those lucky few. I'm sure if the current fans of the show started applying their own interpretation to Doctor Who they would make some mistakes and write one or two controversial things. (And let's not pretend Russel T Davies was perfect!)
In the end, he's not just some geek writing fan-fiction. He's where he is for a reason.