Why do atomic spectra appear as lines?
2 Answers
The light is passed through a narrow slit.
Explanation:
A set-up of a prism spectrometer is shown below.

You'd want the image to be long as it is easier to see. However, you would not want a broad image as the bands might overlap, or even if they do not, their distance of separation would not be well-defined.
Hence, the ideal shape for an aperture would be a long, narrow slit.
Because atoms have quantized energy levels.
Take Infrared Spectroscopy for instance. Its peaks arise from the vibrational modes of molecules, not atoms.
The stretches and bends of bonds alter the dipole moment of the molecule, which is directly proportional to the strength of the IR peak.
IR peaks have width to them because the dipole moment changes while the molecule stretches and bends, changing their electron distribution and altering their receptiveness to the incoming light source; the integral under their peaks is nonzero and not small.
Two examples:

