A gracious follow-up letter will help you stand out from the other applicants and possibly lead to future opportunities. If the newly hired person doesn't work out at the company, for example, they might reach back out to you, or if a new position opens up, your interviewer may be more likely to remember you.
The Ladders calls this a "big boy/big girl" letter, rather than a thank-you letter, but, in essence this is what you should say:
Thank them for considering you for the opportunity, [professional coach Jane Trevaskis] said. Tell them what impressed you about the company or the department you were being considered for. Let them know you would like to keep in touch and would like to be considered for future openings.
Check out the link below for a sample letter and other post-job-rejection strategies.
The Letter to Write When You Don't Get the Job [The Ladders]