Dear student.
Formation of heat takes place due to excitation of molecules when they absorb energy due to the temperature difference. When there is a temperature difference, the energy will flow from higher temperature to lower temperature and cause the heating of the body.
Regards.