Just as readers may read for escapism or for enlightenment, so too do writers write from those motives. It's not really an either/or thing; I think every writer has some degree of escapist in her heart, and some desire in his soul to feel wise and to express that wisdom.
But ultimately, this boils down to one of two main drives urging the writer on. Either he wishes to control the world, or she wishes to understand it.
On the one hand, people who've been hurt or frustrated by reality -- or who are simply bored with it -- can dodge away from the harsh truths of their lives, or else turn the tables on those truths and create new ones of their own by writing. A writer of thrillers or mysteries or war tales may inflict any brutality or revenge he likes upon any conceivable individual he dislikes, at least within the pages of the story. A fantasist or an author of science fiction may flee from our world altogether, journeying to realms limited only by the breadth of her imagination. Fiction (or even non-fiction in some cases) allows these writers to master that which is otherwise beyond their control -- to find freedom where they feel constrained, power where they feel helpless.
If sufficiently talented, such writers may create worlds and tales that are attractive, alluring, even delightful -- and yet in real life they may turn out to be surprisingly unpleasant people. This is true because individuals motivated by a powerful desire to escape or control reality are often going to be very self-centered, inward-looking people.
In contrast, the other end of the spectrum is home to the writer who writes out of a need to understand. This may also be someone who has been antagonized, pained, or bored by existence -- but instead of seeking to deny reality its hold on his or her life, this sort of writer insists that there must be some sort of reason or meaning or purpose to all the suffering, all the grief. Where the other sort of writer wishes to grasp sources of happiness by writing them into her own reality, this sort of writer seeks to measure joy against horror and love against revulsion, in order to find the explanation that makes them all a part of the wonder that is Living.
And here's the most important divider between these two types of writers: the second type is doomed to inevitable failure if he does not possess empathy. The world cannot be understood if one has no talent for absorbing other perspectives, no feeling of kinship for those whose attitudes, ideas, and experiences are fresh and different and even contrary to the writer's own. To accomplish the goal of finding truth, you must take other people into account. In failing to do so, you can paint only delusions.
Unfortunately, not all writers know which sort they are. A great many escapists fancy themselves as seekers instead, imagining that they write Truths instead of crafting mere fiction. Then too, there are explorers who stumble upon their true direction only inadvertently as they try to flee into a realm of fantasy.
None of this is cut-and-dried, separable by way of some dichotomous key that lets us categorize writers and their works cleanly into one of two camps. But it does, I think, help explain why some writers can craft amazing stories about fascinating and virtuous characters engaged in escapades of adventure and romance, and yet remain rather sour and distasteful human beings in their own lives.
If you write because you want to know the world, then you probably also want to know people. And it's hard to really know people without then wanting to be nice to them. (Well ... most of them.)
So the next time you're reading a book, you might try to notice whether the author seems more interested in figuring things out, or in forcing them to do his bidding. A clue is that the escapist will often try to convince you that she is right, while the seeker will generally leave you to your own conclusions.
Conversely, the next time you're reading a book, you might want to forget about this post altogether.
There is, after all, a certain worth in just having fun and not thinking too hard about things.