Maharishi Ved Vyasa wanted to pen down Mahabharata, but he knew that he would not be able to do this alone. So he approached Lord Ganesha to help him to write it.
Ganesha agreed on one condition that He would only write if Maharishi Ved Vyasa would recite it fast and in a continuous flow without stopping in between. Maharishi Ved Vyasa agreed to it but had his own condition- that Lord Ganesha has to understand everything before penning it down so that Maharishi gets to rest in between the recitation.
It is believed that when Lord Ganesha was writing, his pen began to wear away and as He had always proclaimed that He would not be disturbed, He pulled out his left tusk and used it to complete writing the great epic Mahabharata. That's why Lord Ganesha is also called Ekdantaya.