The the flame test is used to identify some inorganic chemical elements, by means of the emission of light by the phenomenon of atomic excitation by the increase in temperature.
In this sense, when an atom is excited, it means that it has left its ground state (in which each electron occupies its place in its orbit, around the nucleus), when this happens some electron jumps out of the orbit it occupied in its fundamental state to an outer orbit, further away from the nucleus and then return to the ground state, emitting in the form of light the energy received.
To understand it better:
An excited electron is an unstable electron, and when passing from one orbit to another, it produces light of a specific wavelength (color) that depends on the amount of energy the electron loses.
This is how the color of the light emitted in the flame is related to a characteristic chemical element.