Towards the end of the program, the Shuttle performed two roll maneuvers during powered flight.
The first, performed throughout the Shuttle program, and known as the "roll program" or "Single Axis Rotation", was actually a multi axis maneuver that mainly served to set the launch azimuth. Since the shuttle stack sat on the pad in a fixed orientation, it is clear that some sort of rotation must be done to point the vehicle in the desired direction. In the ISS era, most of the flights followed the same azimuth to that destination's orbital inclination. You state
I would think better to do it earlier after launch while the air flow pressure is low.
and in fact the roll program occurred as soon as practical after tower clear. In fact, the initiation of this roll program was a cue to the crew that guidance and control was working properly, and hence the call to the ground to acknowledge this "Roll Program, Houston." If the roll program did not occur on time, the crew would have engaged the Backup Flight System redundant control scheme.
It is also important to achieve the proper launch azimuth early in the trajectory because orbital plane changes are very costly in terms of propellant usage.
Because the Orbiter wings developed lift at zero angle of attack, the high dynamic pressure portion of ascent had to be flown at a negative angle of attack, close to the zero lift angle. This could have been done heads-up or down, but the early crew members expressed a preference for having a horizon view. This led to the heads-down attitude.
The other roll maneuver, which was added later in the program, and known as the "roll to heads up", took place in second stage when dynamic pressure was low. This roll was driven by budget reasons - the desire to close a ground tracking and communication site. Rolling to heads up allowed the Orbiter to communicate through a TDRSS satellite instead of the ground station formerly used.
A point of interest here was that since the stack was rolling from almost exactly heads down to exactly heads up, it was not predictable in advance whether the vehicle would roll clockwise or counterclockwise. Small variances in attitude would decide this.
References:
- Space Shuttle News Reference (1988) p.798-799 (pdf pages 814-815)
- STS-087 Post Flight Mission Report page 3 (pdf page 9)