Imagine a container that hold gas at atmospheric pressure at earth's surface. It is elevated by a space elevator to a point high enough that there is a significant pressure difference (but not in orbit). An opening is opened in the container and the gas runs through a turbine generating electricity while it leaves, then falling back to the atmosphere. Gas would return to the atmosphere with lower thermal energy, due to some of it's energy being converted to mechanical or electrical energy.
My question is that if this system converts thermal energy to mechanical or electrical energy, wouldn't this mean that the entropy of the universe would decrease violating the second law of thermodynamics? If the gravitational work that must be done is greater than energy generated by the turbine, what about an atmosphere with a gas of different density?