Because I had some ideas I wanted to work out, and fiction was The Way. Also http://thefuturewedeserve.com which was a massively collaborative book some friends and I put together: really a fun project, quite mind expanding.
I wanted to explore a new topic that didn't have that much material out at the time (Google Wave -> HTML5 Gaming). And I like to speak at conferences, a book helps you get selected more.
My book has done better than most and is still selling decently approaching 2 years since publication but that's the exception , not the rule.
Having said that, my next book(s) will be much more closely tied to my professional career aspirations - the book can serve as a "calling card."
If you do write a book, put in the work to do it well. Please don't use a vanity press!
Most popular were Foundations of Programming, The Little MongoDB Book and The Litte Redis Book. Most recent is Scaling Viki.