Why do we need so many books of the Bible and Bavli if only Torah was written by God (Shemot 24:12 and Shemot 32:32)?
Because the other books were written by the prophets at the command of Hashem (Neviim - Prophets) or with Ruach Hakodesh - Divine Inspiration (Kesuvim - Writings) or for specific reasons. For instance the Book of Ruth was written by Shmuel Hanavi to back up the psak that Ruth was a legitimate convert so that King David was a legitimate king. The Book of Esther was written to establish Purim. The 24 books of the Tanach were canonized by he Anshei Knesses Hagedola (Men of the Great Assembly), which included the last prophets in order to establish which books were legitimate at the end of the Babylonian exile and the start of the second temple.
I notice that you ask about the Bavli as well. This is the question as to why the oral law was written in the Mishna and Talmud and is different from the other question. This is dealt with at length in How and why was the Oral Torah written?
While originally the oral law was forbidden to be written down in order to ensure that each generation learned directly from the previous generation, eventually problems arose because of the persecutions that forced us to write the notes and discussions.
For over a thousand years, from the days of Moses until the days of Rabbi Yehudah the Prince (late 2nd century CE), no one had composed a written text for the purpose of teaching the Oral Law in public. Instead, in each generation, the head of the court or the prophet of that generation would take notes of the teachings which he received from his masters for himself, and teach them orally in public. Similarly, individuals would write notes for themselves of what they had heard regarding the explanation of the Torah, its laws, and the new concepts that were deduced in each generation concerning laws that were not communicated by the oral tradition, but rather derived using one of the thirteen principles of biblical exegesis and accepted by the high court.10 For while there was a prohibition against writing the Oral Torah, it applied only to actually transmitting it through writing; however, one was permitted to write it down for personal use.11
With the rise of the Greek and Roman empires and their persecution of the Jews during the Second Temple era, it became increasingly harder to learn and transmit Torah teachings from teacher to student. Additionally, during this era there were disputes in Jewish law that, due to the increase in decrees against Torah learning, remained unsettled, since doing so would require peace and calm.
By the time the schools of Hillel and Shammai became well established in the century before the destruction of the Temple, disputes on the law had become so widespread that there was fear that it would eventually seem like there were really “two Torahs.” The unsettled conditions prevented the sages of those times from resolving these disputes, or even at least organizing and categorizing them.12
It was not until the days of Rabbi Yehudah the Prince, who enjoyed a strong bond of friendship with the Roman emperor Antoninus, that there was some respite from the Roman persecutions.
Rabbi Yehudah and his colleagues, foreseeing future turmoil and the increasing dispersal of the Jewish people throughout the Diaspora, which would then lead to further uncertainties about the Oral Law, used this period of peace to set about collecting all the teachings, laws and commentaries that had been heard from Moses and which were taught by the courts in each generation concerning the entire Torah. After analyzing these teachings, Rabbi Yehudah composed a single authoritative text that would be available to everyone.
This was the Mishna. The Talmud eventually had to be written to clarify problems in the mishna as it was written in a very terse style, since much of it still remained oral.
The sages of the Talmudic period, known as amora’im, continued to study, expound, clarify and elucidate the Mishnah, as well as developing their own new insights based upon the rules of extrapolation.
Shortly after Rabbi Yehudah’s death, attacks and persecutions against the Jews living in Israel intensified and the migration of Jews to Babylonia increased. This migration included many of the leading sages of the time, including Rabbi Abba Aricha (better known as Rav), one of Rabbi Yehudah’s leading disciples. Other sages and students of Rabbi Yehudah, such as Rabbi Chiya and later Rabbi Yochanan bar Nafcha (who as a young boy attended Rabbi Yehudah’s lectures), remained in Israel. Thus for a while there were major centers of learning, yeshivot, in both Babylonia and Israel, and some amora’im regularly traveled back and forth between them, bringing the teachings of each center of learning to the other center.
Rabbi Yochanan (d. approx. 4050/290 CE) became the leading Talmudic authority in the Land of Israel. He began gathering the teachings and explanations of the post-Mishnaic sages, and this became the basis of what later became known as the Talmud Yerushalmi (Jerusalem Talmud). Subsequent generations of amora’im in Israel continued to add various teachings, especially aggadic (homiletic and non-legal) ones. However, work on the Jerusalem Talmud was halted somewhat abruptly when the Roman ruler Gallus, in the year 4111/351 CE, attacked and devastated the Land of Israel, instituting harsh decrees against the Jews. Most of the remaining sages fled to Babylonia, and the Jerusalem Talmud remained in its rudimentary form.
Meanwhile the centers of learning in Babylonia continued to flourish, and it was not until around the year 4152/392 CE that Rav Ashi, together with his colleague Ravina I, undertook the editing of what was to become the Talmud Bavli (Babylonian Talmud). They gathered the teachings of the earlier sages, organized and clarified their statements about the Mishnah and the discussions of the amora’im on these, and presented these in a logical and comprehensible way.25