Praise be to Allah, and peace and blessings be upon the Messenger of Allah.
This doubt does not harm the person, and in most cases it is one of Satan's whispers intended to cause grief and confusion for the Muslim.
A person who has lived for years praying, fasting, remembering Allah, and testifying in every prayer that there is no god but Allah and that Muhammad is the Messenger of Allah should not pay attention to such doubts. They have already pronounced the Shahada many times during their worship and remembrance.
The scholars also stated that whoever manifests the outward practices of Islam, such as performing the prayer, is regarded as a Muslim, because the prayer itself includes the Shahada and is among the greatest symbols of Islam.
Therefore, a Muslim should not open the door to obsessive doubts by continually asking: "Did I say it? Did I do it? Was my Islam valid?" These are among Satan's ways of misleading people.
Whoever embraced Islam, prayed, fasted, and lived as a Muslim, then years later began to doubt whether they pronounced the Shahada at the beginning of their Islam, should ignore this doubt. It is merely a whisper from Satan. Their Islam is valid, and they are not required to embrace Islam again because of such thoughts.
And Allah knows best.