This won't be the essay but it'll help maybe.
It was an easy way to set up bad guys, and to make Harry a good guy by default.
J K Rowling doesn't like Slytherins. She chose them to be her antagonists, to be the standard by which to measure appropriate behaviour. Want to be a good person? Don't act like a Slytherin.
Of course, she won't say this. Ostensibly all the official traits of Slytherins aren't particularly bad. Ambition. Cunning. Ruthless determination. They're useful, important skills. But throughout the series, we are constantly pushed to accept that these are bad traits, because they are Slytherin traits, and there ‘wasn't a dark witch or wizard that went bad that wasn't in Slytherin' despite this being blatantly untrue.
Harry choosing Gryffindor over Slytherin is supposed to represent the idea that ones choices are what makes someone a good person, rather than their circumstances, which is a theme repeated often throughout the books. Unfortunately, J K Rowling doesn't seem to believe that cunning or ambitious people can or will make that choice. Even when Snape does act in a good manner, it's then immediately said that ‘perhaps we sort too soon', as if acting like a good person suddenly made him less Slytherin.
So yeah, tangential rant but basically it was a way to push him down the path of the hero, and to set up the idea that being brave would be enough to get you through all life's perils, and to reinforce the idea that he has to be a good person, because he chose not to go sit with the evil kids.
Harry is supposed to be a foil to Voldemort, a reflection on the choices he could've made but didn't. Both Half-blood, both muggle-raised, both abused, but with Harry choosing loving his new world over hating his old one. It doesn't quite translate, because there's significant differences between Harry's and Voldemort's situations, but it was the intention. The sorting is the first step Harry takes away from following the path Tom Riddle laid down, thus portraying that for all their seeming similarities, Harry is fundamentally good, where Voldemort is just evil. Y'know, because he's Slytherin.
by someone named Alex Knight