Why did William Golding write "Lord of the Flies"?
Golding once asserted in an interview that the theme of Lord of the Flies is "an attempt to trace the defects of society back to the defects of human nature. The moral is that the shape of society must depend on the ethical nature of the individual and not on any political system however apparently logical or respectable."
If we take the above comment to be an accurate representation of Golding's intentions (and a comprehensive explanation as well), the answer to the question of why Golding wrote Lord of the Flies becomes one of philosophical commentary on human nature. He wrote the novel to prove a point (or to explore a point) regarding (1) the nature of society and (2) the flaws in human nature that contribute to the flaws in society.
The novel might be taken to suggest that brute nature can exert itself over and against civility when a brute nature offers an equally cogent and sensible mode of interpersonal relations. Considering how well Jack does and how poorly Piggy and Ralph do, one might pause to wonder if the animalism and tribalism that Jack advocates isn't the more functional way to organize a group of boys on a wild island.
Civilization, in a well-populated and highly regulated nation-state, is the more sensible mode of being when organization and civility provide superior degrees of safety and sustenance to people than tribalism would. On an island with no infrastructure whatsoever and no clear practical reason to be civilized, the darker side of human nature wins out--because it is as powerful as man's higher nature or because it is man's truer nature?
Regardless of our answer to the question of why man's brute nature wins out on the island, the fact remains that the ethical core for the boys is not so fully developed toward civility that it might present a valid, compelling alternative to base emotions--aggression, competition, and avarice.
The main reason he wrote the book was probably due to his having served in the British Navy during World War II. He saw some horrific events during his time in the Navy including the D-Day landing at Normandy and the sinking of the German battleship, the Bismarck and battles with other ships. After witnessing all that he did, he commented that "man produces evil like bees produce honey." Since Lord of the Flies is about man's basic evil nature that is only tamed and held in check because of the rules of civilized society, it seems a logical connection to make. Also, Golding had read the book, Coral Island, which is about three British boys shipwrecked on a deserted island having to fend for themselves and doing so peacefully in an ideal setting. Golding, after having seen the horrors man inficts upon man, and seeing how even the "good guys" can become savage, decided to use a similar setting only showing the side of people he thought to be the true side. He wanted his boys to act as he thought real boys might act in that situation.