Fiqh-us-Sunnah Volume 1, Purification and Prayer, Fiqh 1.017A.

Section : One should mention the name of Allah and seek refuge in Him when entering the privy or removing his clothes to relieve himself.

Anas reported that when the Messenger of Allah, upon whom be peace, entered the privy he would say, “In the name of Allah. O Allah! I seek refuge in you from male and female noxious beings (devils).” This is related by “the group.”