Imam Bayhaqi said a detailed Hadith in Dalail-un-Nubuwwah the brief points of which are that Sayyiduna Abu Dujana رَضِیَ اللہُ تَعَالٰی عَنْہ made a complaint in the court of Rasoolullah صَلَّی اللہُ تَعَالٰی عَلَیْہِ وَاٰلِہٖ وَسَلَّمَ about Jinns that disturb him at night so he صَلَّی اللہُ تَعَالٰی عَلَیْہِ وَاٰلِہٖ وَسَلَّمَ gave him order to bring a pen and paper and asked Sayyiduna Ali رَضِیَ اللہُ تَعَالٰی عَنْہ to write a few words from holy words.
After that, Abu Dujana رَضِیَ اللہُ تَعَالٰی عَنْہ folded that paper, brought it home with him and put it under his pillow before going to sleep. At night, he heard the screams of Jinns, who begged him to put the taweez away. In the morning, he discussed that situation with Rasoolullah صَلَّی اللہُ تَعَالٰی عَلَیْہِ وَاٰلِہٖ وَسَلَّمَ.
The Holy Prophet said, “O Abu Dujana, take that taweez away from them for Allah has sent me with truth, that nation (Jinns) will be in pain until the Day of Judgment.”