The Torah is also known as the Pentateuch. Penta (of course) is a prefix which means "five." The Torah is the first five books of the Bible. Those books are also referred to as the "Books of Moses."
Moses was obviously a busy guy. But he was very old and lived in the desert. What else did he have to do? Outside of spending forty days up in the mountains getting the Ten Commandments, he had a lot of time to write.