Difference between flame test and ability to show photoelectric effect
I think you have a misconception. Observing an emission spectrum and photoelectric effects are different things. Photoelectric effect requires not only the electron is ejected with some kinetic energy, but it is ejected by light of a suitable wavelength. No heat or flame is involved.
In (Bunsen burner) flame emission spectroscopy, your temperature is not high enough to remove electrons from Mg atoms in the gas phase. Eventually, the flame temperatures can be made high enough that you do start to observe emission from Mg atoms, but it is in the UV range. Your eyes cannot see UV light.