Most birds you see standing on only one leg are doing an impressive balancing act while tucking the second leg into their feathers. This is much easier to recognize in large birds, such as flamingos, but the behavior itself is common to most birds. So, the real question is: why do they do that?
The answer is that birds use their feet for temperature regulation. In most birds the legs and feet are unfeathered, and thus lose heat very quickly — the same way your exposed hands get cold in winter faster than your clothing-covered torso. That makes the bare feet great conductors: when the bird’s overall body temperature is too high, it can cool off by standing on both legs and letting the wind carry away heat. When the temperature drops too low, it can pull one leg up and lose less heat. Finally, it can sit down and cover all the bases.
Many birds are able to control the amount of blood flow through their legs, which increases their ability to regulate temperature. The only danger comes in standing around on a cold day: with one foot tucked up and blood flow greatly reduced to the other, there is a possibility that the exposed leg will freeze. This can be countered by staying in a nest or, in aquatic birds, by going into the water. As long as the water is in a liquid state, the bird legs floating in it can’t freeze.