This is an area of active research. Right now a lot of effort is being directed toward understanding the genetic basis for feather development and evolution, to see how they evolved from the original scales/skin of reptiles. That's probably a necessary precursor to understanding why they evolved.