It really doesn't matter why it was written..
The point is, that "the church" chose 4 Gospels with a certain agenda.
There were many, many Gospels.
While I would agree that there are many gospels, those many weren’t written in the same century as when Jesus’ apostles and disciples.
Many of were composed in the 2nd century CE and some even later that.
The names attributed to these later gospels, were “attributed to” these people, but they do not mean attributions were the actual authors to these gospels.
The real authors are unknown.
Those four gospels accepted in the New Testament, are also anonymously written, but the names of the evangelists were ascribed around the earlier 2nd century CE.
But these 4 accepted gospels are among the oldest gospels, and “fairly reliably” dated to the 2nd half of the 1st century CE.
Among the non-canonical gospel that “may” be dated to the century as the canonical gospels, is possibly the gospel of Thomas.
I must stress the word that I quoted “may”.
Scholarly, the gospel of Thomas appeared to 1st century gospel, but the extant source is actually an early 2nd century CE “copy”.
So if it is copy, then the original is lost. And if there were an original gospel of Thomas, then it could be as old as the gospel of Mark (the Mark gospel has been dated between 65 and 75 CE).
There are numbers of copies of gospel of Thomas discovered in Egypt.
Several were found in Nag Hammadi. A whole bunch of Gnostic codices were hidden at Nag Hammadi, to hide it from the Orthodox Christians (Pauline Christians), who were burning Gnostic texts during the 3rd-4th centuries CE. Here, the copies were written in Coptic.
But older fragments made from papyrus (written in Greek) was discovered at Oxyrhynchus.
The Greek copy has been dated to the 2nd century, while the Coptic version some where between mid-3rd to mid-4th centuries CE.
Like I said, even the Oxyrhynchus fragments are copies, so there must be earlier version, perhaps an original.
The rest of the Apocryphal gospels as well as the Gnostic gospels are clearly dated later than the 1st century CE, so their authenticity are surely not reliable. The gospel of Thomas is the only gospel that an open question mark.
PS
Do I think the gospel of Thomas was written by apostle Thomas?
Well, my answer would be “no”.
Thomas didn’t write this gospel any more than Matthew and John wrote the respective gospels that were ascribed with their names.