By heating metal you are providing sufficient energy for the excitation of electron from specific orbital to another high energy orbital but after a very small and i meant a very small period of time the electron de-excites to lower energy orbital releasing energy of specific wavelength. So by changing or varying temperature and providing heat to metal the electron continuously excites and dexcites providing different wavelength of light.