Adam Mansbach wrote it after a hard night of trying to get his 2 year old to go to sleep... Well, actually he jokingly said he was going to write it then people encouraged him to write it.
The full story of the book (including how its publishing date was pushed up because a pre-release pdf was being forwarded around) can be found at:
http://en.wikipedia.org/wiki/Go_the_Fuck_to_Sleep