Well, they do produce photons in the same way metals do, they just have different energy level gaps. The light in a flame test comes from electrons being excited up to higher energy states by the energy in the flame, and then they drop back down to their ground states. When they drop back down, they emit a photon of the same energy as the energy gap between the ground state and the one they got excited to. This is the light you see.
The reason you don't see light from chlorine is that the energy gaps don't correspond to the wavelengths of visible light, but they are still there.