The dua to be recited before undressing was taught by Prophet Muhammad (ﷺ) as reported by a Hadith in Jami at-Tirmidhi 606. The narrator of the Hadith is Ali Bin Abi Talid (رَضِيَ ٱللَّٰهُ عَنْهُ), who reported the Prophet (ﷺ) saying: "The screen between the eyes of the jinns and nakedness of the children of Adam when one of you enters the area of relieving oneself is saying: 'Bismillah.'" – Jami at-Tirmidhi 606.
One should still recite Bismillah before entering the toilet or an area where you are going to undress. This is because commencing any action or job with the recitation of Allah (سُبْحَانَهُ وَتَعَالَى) 's name is bound to bring you blessings and ward off Shaytan and evil.
It is recommended to recite this dua before you enter the toilet, or if you're in your room, recite it immediately before you undress. However, if you're changing in the toilet, make sure to recite the dua before you step inside the toilet, as the area or place where you recite any dua should be clean in order to mention Allah (سُبْحَانَهُ وَتَعَالَى) 's name or the Quran.
"Uthman b. Abu al-'As Al-Thaqafi reported that he made a complaint of pain to Allah's Messenger (ﷺ) that he felt in his body at the time he had become Muslim. Thereupon Allah's Messenger (ﷺ) said: Place your hand at the place where you feel pain in your body and say Bismillah (in the name of Allah) three times and seven times A'udhu billahi wa qudratihi min sharri ma ajidu wa uhadhiru (I seek refuge with Allah and with His Power from the evil that I find and that I fear)." Sahih Muslim 2202