Whether our Messenger (peace be upon him) was illiterate his whole life or a part of it or what exactly is the meaning of illiterate is are Questions which i won't explain here, but i just want to let you know that they are well discussed matters among Muslim scholars!
I will try to explain how the Quran was written at the end of my answer but first i want to explain the meaning of the word:
The meaning of the words Quran and Mushaf
Quran (القران): al-qurʼān, literally meaning "the recitation"is the word of Allah that is recited verbally.
So the Quran has been transmitted through the time by oral memorization and recitation on a hand of Scholars beginning with the Sahaba (May Allah be pleased with them) and not through a book (even today), and those who learned the Quran only through books are not accepted as teachers of a reading if their Reading isn't approved by a Sheikh/Scholar who has a direct Narration chain until our Messenger (peace be upon him)!
So when the Messenger of Allah (peace be upon him) died the Quran was not compiled in a book but memorized in first place by many hufadh/hufaz (memorizers) among the sahaba (May allah be pleased with them) (see for example this hadith narrated by Hammam, Qatada and also by Anas (May Allah be pleased with them)!
Mushaf (المصحف): is the written form of the Quran or the book. It's usually what is meant when people talk about the Quran!
The first time the Quran was collected in written format was at the time of Abu Bakr (First Caliph). The reason Abu Bakr ordered the collection of the Mushaf is that there is a large number of the holder (memorizers) of the Quran whom had martyred in the battle of Yamamah and Abu Bakr was worried that he might Quran by lost with the death of the memorizers (See here and here).
'Othman (May Allah be pleased with him) ordered the collection for the 2nd time of the know Quran into a book to maintain the knowledge in written format as well. And to help those from non Arab origins, who joined Islam recently, to be able to read and learn (See for example here). The difference between the 2 version is the quality of the writing and the materials used for the book but the content was the same as they were collected by the same person (Zaid Ibn Thabet).
The Mushaf that was collected by 'Othman didn't have dots that are present in the current Arabic language letters. And that how the Arabic letters were written at that time. You might ask how would they know how to differentiate between the words? The answer it was kind of understanding that an Arab would right away spot the word and understand the actual mapping. Dots were introduced latter in the time of Omayyad's Caliphate because the people of non-Arab background didn't recognize the writing (see "Pre-Islamic Arabic inscriptions" here). And the Arabic Alphabet and the Mushaf have seen further developments later!
Written Quran fragments written by scribes during the lifetime of the Prophet (peace be upon him)
The collection of the Quran and it's compilation in a book after the death of the Prophet (peace be upon him) doesn't mean that the Quran has never been written down before! There have been written pieces of it in the hands of those who have been called the writers of divine revelation as we can conclude from this statement from the two ahadith narrted by Zaid ibn Thabit (May Allah be pleased with him) mentioned above
So I started looking for the Qur'an and collecting it from (what was
written on) palmed stalks, thin white stones and also from the men who
knew it by heart, till I found the last Verse of Surat at-Tauba
(Repentance) with Abi Khuza`ima Al-Ansari, and I did not find it with
anybody other than him
and from other ahadith for example here where the Prophet (peace be upon him) ask for a scribe to write some new revelation, here where it's said not to travel to the land of enemies with a Quran (=Mushaf), here where Zaid ibn Thabit (May Allah be pleased with him) describes how or more exactly where the Quran was written and finally this hadith in which our Messenger (peace be upon him) ask the sahaba not take down anything from him except the Quran, so our Messenger (peace be upon him) used to dictate the new revelations and some sahaba who could write where his scribes and they used any clean object like leather, bones etc. to write on it and therefore some Quran fragments have already existed during his lifetime, and this are those which Zaid ibn Thabit (may Allah be pleased with him) collected during the reign of Abu Bakr (may Allah be pleased with him)!
Conclusion: The Prophet Muhammad (peace be upon him) had scribes who wrote for him, what he dictated and memorizer's who memorized it at the same time!
And Allah knows best!