In Sahih al-Bukhari it mentions that the Prophet (PBUH) wanted to write a statement after which the Muslims would not go astray after him. But wasn't the Prophet (PBUH) illiterate? What is the explanation for this narration?
According to Twelver Shi'i belief, the Prophet had the knowledge of writing but did not do it.
In any case, this may be a technicality. In those days, people often dictated their letters rather than writing them themselves. So he probably would have given the pen to someone and told them what to write.