Escaping predators, small dinosaurs have certainly develop a way to glide when jumping from tree to tree. Some squirrels still do it today. One can imagine that, in the course of evolution of the survival of the best fitted, that ability to sustain airborne distances, increased to the point that they managed to gain altitude. Incidentally, still today, many birds use thermal convections to gain altitude, such as soaring eagles and seagulls.
As a light aircraft pilot, I started with gliders, a very good school to aviation. When in a glider, we also use thermals to gain altitude. Usually that are to be found under cumulus clouds. If we spot e.g. seagulls circling there, we know that we can join the roundabout and gain altitude.
There are HUGE survival advantages to flying (which is why so many insects, and even some mammals, fly).
They can escape predators -- all that can't fly, and those who also fly (because flying is 3-dimensional); get places more directly, to increase their access to food, water, and home-building materials.
Because they can't afford to buy train tickets.
To get to the other side?
Why do cows moo? Why do fish swim? Why do snakes slither?... They just do!
because they are built for it, they have a keeled sternum, hollowish bones, and feathers.
Because they can.