I personally have never had this particular problem, but just thinking about it, is it possible for him to get out of the situation where he is most often tempted? Like maybe if he has a temptation while trying to fall asleep, maybe he should develop a habit of getting up and praying or reading or doing something until he overcomes it. If it is during the daytime, maybe he could try going for a walk or go someplace public so that social norms would prevent him. If it is in the shower, then maybe he should try to compete with himself to try and see how fast of a shower he can take, and therefore have less time to be in there with those thoughts.