The simple answer of course is because we have to. I write because my characters can't and their stories deserve to be told. I just read a blog by someone who will remain unmentioned that said writers are not artists. Now of course they were talking about the cover of a book and how a writer should have input but not get overly involved, so I'm taking it a bit out of context. However, I still don't like the statement in general. We are artists, you only have to read a truly moving book to know that. However, the reason why you're writing (and of course your skill level) will determine whether you're a paint by numbers artist or Michelangelo.
Do you write what you love, do you write what you know, or do you write what sells? You can pretty much tell which method a writer followed by reading their book. When writers write what they love it's usually a very compelling story, one that keeps you up at night turning pages. Writing what you know can resonate with a bit of the god complex if you're not careful though. Certainly not always, I often enjoy reading books by authors who write what they know. As long as the writer allows the story flow on it's own path rather than the one they think it should flow on, then it reads true. Writing what sells can be hard, especially if it isn't something you'd normally write. I can really tell when I pick up a book if it's been written for this soul purpose. They're often dry and feel forced.
The best scenerio is to know about what you love to write and it just happens to be what's selling at the time. How lucky would that be?! The good news is, most of us know about what we love because we read about it or live it. So, as difficult as all that sounds, you most likely already have the first two down, which is the recipe for a great book. The rest is all up to timing and the market!