I shall try to help you, however my technical English is quite bad, so bare with me
First step: Nucleophilic attack by the alcohol group on acyl chloride. acyl chlorides are quite reactive, so that is why the reaction takes place.
Second Step: Chlorine is a good leaving group, because it`s conjugated acid (HCl) has a small pKa. Therefore the carbonyl (C double bonded with O) is favoured and thus the Cl is expelled.
The pKa thing is more of a helper in determining leaving group ability rather than an explanation of why it happens.
Hope I helped!