It was to tell them apart. There were originally only going to be two colors: Red and blue. Then someone decided that since Luke gets a new saber in ROTJ, it should be a new color. Then when the prequels were made, Georgy had to incorporate Samuel L. Jackson's demand request to have a purple saber.
And if you happened to have read the original script, Georgy wanted to have Stormies using lightsabers too. And they were gonna be the same color (I think).
Just another thing I love about this forum: everybody knows so much cool stuff! Stormtroopers with lightsabers would have been freaking sweet.