Abu Dawud Book 1, Hadith Number 4.
Chapter : What should a man utter while entering the privy.
Narated By Anas b. Malik : When the Apostle of Allah (PBUH) entered the toilet, he used to say (before entering) : “O Allah, I seek refuge in thee.”
This is according to the version of Hammad. ‘Abd al-Warith has another version : “I seek refuge in Allah form male and female devils.”
Explaining the variance of the version Abu Dawud says : Shu’bah on the authority of ‘Abd al-‘Aziz narrated: “O Allah, I seek refuge in Thee,” and sometimes he reported: “I take refuge in Allah.” Wuhaib (b. Khalid) (on the authority of ‘Abd al-‘Aziz) narrated: One should take refuge in Allah.