Welcome to HealthcareMagic,
Here I guess your friend probably has OCD or what is called Obsessive-compulsive disorder
It is an anxiety
disorder in which people have obsessions like unwanted and repeated thoughts, feelings, ideas, sensations, that make them feel compelled to do something.
If your friend has this disorder he can consult a Psychiatrist
and if needed he may start on medicines for the same.