All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and messenger.
Writing anything from the Quran or Thikr on the shroud of the deceased or the wrapper which is wrapped over the shroud and is not buried in it was not done by the Prophet, sallallaahu ‘alayhi wa sallam, with any of the martyrs or anyone else. The Companions did not do this with the Prophet, sallallaahu ‘alayhi wa sallam, when he died in his shroud or the shroud of anyone else. This is not one of the things by which the dead are honored. Honoring the dead is to wash, shroud and bury his dead body according to the Sunnah. So, this is not valid under Sharee‘ah. It is also impermissible to bury the deceased in such things in order not to disgrace the speech and mention of Allaah The Almighty.
Ibn As-Salah was asked about this and he prohibited it. Here is the context of the question and answer: “A question about the shroud: ‘Is it permissible to write on the shroud any Soorah of the Quran say, Yaa-Seen, Al-Kahf or such or is it unlawful lest the pus of the deceased may flow on the Quranic verses and the blessed noble names of Allaah The Almighty? Is it permissible to place with him in the grave any stitched garment?’
The answer: ‘This is impermissible. Stitched clothing is permissible and so being shrouded in a shirt and Allaah The Almighty Knows best.’” [Fataawa Ibn As-Salah]
Commenting on this, Ibn Hajar Al-Haythami said, in his Al-Fataawa Al-Fiqhiyyah Al-Kubra: “Ibn As-Salah gave a fatwa that it is impermissible to write anything of the Quran on a shroud in order to maintain it from the pus of the deceased. The same impermissibility applies to such writing as they call Kitaab Al-‘Uhdah. The opinion of Ibn As-Salah was concurred by the Imaams after him. The meaning is very apparent. The Quran and exalted names as the Names of Allaah The Almighty and the names of His Prophets, may Allaah Exalt their mention, should be respected, venerated and exalted. Indeed, to write such and make it part of the shroud of the deceased means to disgrace it since no disgrace is greater than contamination. It is well known that anything placed in the shroud of the deceased is affected by his blood, pus or any such filth coming from his body. So, the prohibition of placing in the shroud of the deceased anything in which an exalted name is written is decisive.”
According to the statement of the learned scholar, Al-Jamal Ash-Shaafi‘i, “It is impermissible to write on it (i.e. the shroud) anything of the Quran or the exalted names (of Allaah The Almighty and His Prophets), in order to maintain them from pus and other such things.”
Whoever does so as you have mentioned in your question is expected to do it with a good intention and out of wishing for good. But, this alone is insufficient to make any deed valid under Sharee‘ah. Thus, it is due to follow what is valid, under Sharee‘ah, in the shroud of the deceased and give up what is unlawful.
Allaah Knows best.