Lord Ganesha wrote Mahabharata, as mentioned in the other answer by @CDR.
Mahabharata was composed by Vyasa much before but it was penned down by Lord Ganesha in human world after the war was over and Dhitrashra, Vidura etc left. Again, it was narrated 1st time in human world after the Sarpa yagna by Janmajeya. Many people later re narrated it and Sauti (Ugrshava) was one of them.
MBH 18:05:46.:
“In former times, the great Rishi Vyasa, having composed this treatise (Bharata), caused his son Suka to read it with him, along with these four Verses…”
Now, if we see Mahabharata, Suka got liberated much much before the war.
MBH 12:320:32-36.:
“Consoling the Island-born Rishi who was burning with grief on account of his son, Mahadeva said these words unto him.–Thou hadst formerly solicited from me a son possessed of the energy of Fire, of Water, of Wind, and of Space; Procreated by thy penances, the son that was born unto thee was of that very kind. Proceeding from my grace, he was pure and full of Brahma-energy”.
“He (Suka) has attained to the highest end (moksha)–an end which none can win that has not completely subjugated his senses, nor can be won by even any of the deities. Why then, O regenerate Rishi, dost thou grieve for that son? As long as the hills will last, as long as the ocean will last, so long will the fame of thy son endure undiminished!”
This Life story of Suka, was narrated to Bheeshma by Vyasa and Narada in ancient times. Which he later narrated to Yudhishthira when he was on his arrow bed.
MBH 12:320:39-40.:
“I (Bheeshma) have now told thee, O chief of Bharata’s race, everything regarding the birth and life of Suka about which thou (Yudhishthira) hadst asked me. The celestial Rishi Narada and the great Yogin Vyasa had repeatedly told all this to me in days of yore when the subject was suggested to him in course of conversation”.
So, Vyasa composed the Mahabharata much before the war itself but it was penned down later on. Also, Mahabharata was narrated in other worlds and to other beings like Devas, Yakshas, rakshasas etc much before it was narrated to humans and every loka have additional verses.
MBH 1:01:53-58.:
“Sauti continued, ‘I will now speak of the undying flowery and fruitful productions of this tree, possessed of pure and pleasant taste, and not to be destroyed even by the immortals. Formerly, the spirited and virtuous Krishna-Dwaipayana, by the injunctions of Bhishma, the wise son of Ganga and of his own mother, became the father of three boys who were like the three fires by the two wives of Vichitra-virya; and having thus raised up Dhritarashtra, Pandu and Vidura, he returned to his recluse abode to prosecute his religious exercise. It was not till after these were born, grown up, and departed on the supreme journey, that the great Rishi Vyasa published the Bharata in this region of mankind (through Ganesha); when being solicited by Janamejaya and thousands of Brahmanas, he instructed his disciple Vaisampayana, who was seated near him; and he, sitting together with the Sadasyas, recited the Bharata, during the intervals of the ceremonies of the sacrifice, being repeatedly urged to proceed”.
MBH 1:01:61-64.:
“Vyasa executed the compilation of the Bharata, exclusive of the episodes originally in twenty-four thousand verses; and so much only is called by the learned as the Bharata. Afterwards, he composed an epitome in one hundred and fifty verses, consisting of the introduction with the chapter of contents. This he first taught to his son Suka; and afterwards he gave it to others of his disciples who were possessed of the same qualifications. After that he executed another compilation, consisting of six hundred thousand verses. Of those, thirty hundred thousand are known in the world of the Devas; fifteen hundred thousand in the world of the Pitris: fourteen hundred thousand among the Gandharvas, and one hundred thousand in the regions of mankind. Narada recited them to the Devas, Devala to the Pitris, and Suka published them to the Gandharvas, Yakshas, and Rakshasas: and in this world they were recited by Vaisampayana, one of the disciples of Vyasa, a man of just principles and the first among all those acquainted with the Vedas. Know that I, Sauti, have also repeated one hundred thousand verses”.
Q.: How did Krishna Dvaipayana Vyasa knew about the future.?
A.: it's because he had the knowledge of Past, Present and Future.
MBH. 13-49-45.:
"'Parasara said,—"In former times I gratified Sarva, O king. I then cherished the desire of obtaining a son that would be possessed of great ascetic merit, endued with superior energy, and addressed to high Yoga, that would earn world-wide fame, arrange the Vedas, and become the home of prosperity, that would be devoted to the Vedas and the Brahmanas and be distinguished for compassion. Even such a son was desired by me from Maheswara. Knowing that this was the wish of my heart, that foremost of Deities said unto me,—'Through the fruition of that object of thine which thou wishest to obtain from me, thou shalt have a son of the name of Krishna. In that creation which shall be known after the name of Savarni-Manu, that son of thine shall be reckoned among the seven Rishis. He shall arrange the Vedas, and be the propagator of Kuru's race. He shall, besides, be the author of the ancient histories and do good to the universe. Endued with severe penances, he shall, again, be the dear friend of Sakra. Freed from diseases of every kind, that son of thine, O Parasara, shall besides, be immortal.'—Having said these words, the great Deity disappeared there and then. Even such is the good, O Yudhishthira, that I have obtained from that indestructible and immutable God, endued with the highest penances and supreme energy."
Sri Shiva Purana 5.2.15.:
- The sage Vedavyāsa who had acquired unequalled glory propitiated him and attained knowledge of the three times—past, present and future.
Conclusion.: As, i have already mentioned in answer of mine that Mahabharata was composed by Vyasa after the completion of all the 18 puranas and as all the puranas tells stories of different different kalpas and on top of that Bhavishya Purana tells about the stories of future. So, one can see that it's no surprise that Vyasa recited and Lord Ganesha wrote about some future incident regarding Mahabharata and about them.
I hope this clarifies all your queries. Prd..