There are probably as many reasons for writing war literature as there are pieces written, but we can generalize about some of the most important reasons.
If we survey the entire canon of war literature, I think we would conclude that most writers of war literature are former participants in who want to document their experience, in part to help themselves deal with horrific experiences and to tell others what they went through. Many writers of war literature have discovered that the act of writing helps them deal with what we know call Post Traumatic Stress Syndrome. Another group of writers have an agenda--they either wish to persuade readers that a particular war was or wasn't the right war to fight or they simply want to record for history what went on at a strategic or tactical level in a war.
Aside from books on war written from a strategic level, read in order to understand how a war was fought on a grand scale, the war literature that leaves an impression on individual readers is often those stories written in the first person or by a participant who is describing how war affects individuals, both physically and mentally. For example, Tim O'Brien's The Things They Carried or Karl Marlantes' recent book Matterhorn provide us with a first-hand, grim account of what the Vietnam War was like for average soldiers and Marines. Through the reading experience, we experience vicariously what they went through, and that experience gives us a perspective on the war that we could not obtain any other way. These are the books, rather than the high-level histories of war, that allow us to "feel" what it was like to be a combatant, to feel the horror of anonymous violence, to feel the frustrations with command decisions that don't make sense on the ground.
In the end, war literature has many purposes, but perhaps the most important purpose is to teach us that if we decide to put our troops into war, we ought to have a very good reason for doing so.