The thionyl chloride method is preferred over hydrogen chloride or phosphorous chloride method for the preparation of haloalkanes because both the by-products (SO2 and HCl) in this case are gases and escape leaving behind pure chloroalkane. This reaction takes place in the presence of
Pyridine
Pyridine molecule act as a catalyst which is used to neutralise HCl formed.Pyridine also acts as a nucleophile because in the reaction proton is added to alcoholic O due to strong electronegative
SOCl2 group and proton is removed by pyridine and reforms S=O and Cl- is removed from SOCl2.This Cl- ion reacts with electrophilic C atom of alcohol and displaces SO2 and another releases another Cl-
Ion which makes alkyl chloride.