أَخْبَرَنَا إِسْحَاقُ بْنُ إِبْرَاهِيمَ، قَالَ أَنْبَأَنَا إِسْمَاعِيلُ، عَنْ عَبْدِ الْعَزِيزِ بْنِ صُهَيْبٍ، عَنْ أَنَسِ بْنِ مَالِكٍ، قَالَ كَانَ رَسُولُ اللَّهِ صلى الله عليه وسلم إِذَا دَخَلَ الْخَلاَءَ قَالَ ‏"‏ اللَّهُمَّ إِنِّي أَعُوذُ بِكَ مِنَ الْخُبُثِ وَالْخَبَائِثِ ‏"‏ ‏.‏

It was narrated that Anas bin Malik said: "The Messenger of Allah (PBUH) entered Al-Khala' (the toilet) and said: 'Allahumma inni a'uthu bika min al-khubuthi wal-khaba'ith (O Allah, I seek refuge with You from male and female devils)."[1] [1] See Ma'alam As-Sunan by Al-Khattabi. And Al-Khala' is the area one relieves oneself in. It refers to outside or other than that, it should not be understood to mean toilet only. Translation Not Available

Book Ref: Sunan An Nisai Book 1 Hadith 19
Web Ref:  Sunan An Nisai Vol 1 Book 1 Hadith 19