Why does the test tube face downwards in gas production?
If you mean the test tube containing the solids (reaction tube), then that tube faces downwards to promote the flow of gas into the receiving tube.  The idea is to let the gas sink away from the reaction zone and towards the receiving tube as it cools and becomes more dense.

The receiving tube, of course, faces down so that the ammonia gas, lighter than air, can float to the top after it meets the air.  So you have the ammonia flowing down with cooling through the reaction tube and then flowing up with buoyancy into the receiving tube.

Now for my bonus question:  Had you been producing carbon dioxide by heating magnesium carbonate, would you change the reaction tube?  How about the receiving tube?