There are many reasons for writing a formal letter:
Resignation Letter: needed when leaving a job
Recommendation Letter: for when applying to a new job or university
Reference Letter: to explain why someone is a good candidate
Complaint Letter: if something has gone wrong
etc.