In Newton's classic experiment, when light is passed through a slit and then through a prism, because of the variation in refractive index with wavelength (called the dispersion of the glass), every wavelength of light will be refracted slightly differently and the original light spread out into a band of rainbow colours. In effect, there is a separate image of the slit for each wavelength. When the light from flames is examined, instead of full bands of colours, narrow lines of specific colours are seen - the emission lines. Each element has a specific set of lines, and so the field of spectroscopy was born. A number of elements were first found by their emission lines - Helium, Thallium, Cerium etc.
The reason for the lines being so specific for each element were first explained by the Bohr model When electrons move from one atomic orbital to a lower energy state, the resultant energy is packetized as a photon with a certain frequency. For simple elemental light sources, the energy states are very specific, and so are the frequencies of light that are observed.
See also spectral line