Why was it necessary to have an oral law? Couldn't we have avoided inaccuracies and machlokot in the mishnah, gemara and etc by writing it down originally?
The Rambam in Moreh Nevochim 1:71 addresses this question. The Rambam actually says that the opposite is true - the integrity of the Oral law was preserved specifically by it's being oral. The Rambam writes as follows (קאפח edition):
וכבר ידעת כי אפילו תורה שבע"פ המקובלת לא היתה כתובה לפנים, כפי הצווי המפורסם באומה "דברים שאמרתי לך על פה אי אתה רשאי לאמרם בכתב", והרי זו היא תכלית החכמה בתורה, לפי שהיתה הרחקה ממה שאירע בה בסופו של דבר, כלומר רבוי הסברות והסתעפות השטות, ומשפטים בלתי ברורים שיארעו בהסברת המחבר, ושכחה שתארע לו, ויתחדשו מחלוקות בין בני אדם ונעשים כתות ונבוכים במעשה. אלא נמסר בכל זה לבית דין הגדול
(My rough translation) : Of course you are aware that even the Oral Torah which we have received was not originally written down, according to the accepted command "that which I have said to you orally you are not allowed to say in writing," and this is the epitome of wisdom by the Torah, as it serves to fend off that which eventually ended up happening, namely abundance of [conflicting] lines of reasoning and branching off of opinions, unclear statements through the explanatory skills and forgetfulness of the author, and disagreements arise and they become splintered groups, and what should be done becomes unclear. Rather, the entire system was given over to the Great Court.
As R' Yaakov Weinberg explained, a role of the Sanhedrin, as custodians of the Oral Law, was to explain it to the contemporary generation. Oral Law was specifically meant to be communicated in modern parlance, with examples that were clear to the person to whom they were being given. Oral Law was specifically not meant to be codified into static passages which would not have the same meaning in different cultures and periods. The system of Oral transmission forced that the Torah was given over in contemporary terms, face to face with a live person who would explain it in a way that you understood it.
It was only when this system broke down, and the ability to maintain the actual body of knowledge became impractical, that the risk of losing the content of the Oral Law overrode the method that guaranteed its clarity of transmission. This led to the current system, in which set-in-stone phrases become subject to the debate of their meaning, and different paths of reasoning in order to make sense of unclear statements emerge.
To just answer your question:
1- Because no finite text could fully describe what it the right answer for every situation and every context a human being might face. Therefore, Hashem gave Moshe a system, not a set of halachic conclusions and agadic guidelines. Something with which human beings can derive the rest.
2- No finite text could capture Hashem's Thought anyway.
3- The whole point of Torah study is the exercise of figuring answers out. G-d didn't want Torah study to be memorization. This is why we still study gemara, rather than just skip to the chase with the Rif's selection of its conclusions, or study just the Rambam's Mishneh Torah or the like.
Hashem gave Moshe a process for humans to work. This is why, in the tanur shel akhnai story (Bava Metzia 59a-b), even though R' Eliezer is capable of invoking miracles "if I am correct", the law still follows the majority against him. Halakhah follows the process given, the kelalei hapesaq -- the rules of decisionmaking, not revalation of Divine Truth. The debate concludes by quoting the verse "lo bashamayim hi -- it is not in heaven", because Hashem didn't intend to give us answers. And the story concludes with us learning that at that moment Hashem laughed (so to speak) "Nitzchuni banai -- My children have bested Me / My children have eternalized Me".
He intended to give us the tools with which to grapple with the question and work toward an answer. That is more important than always getting the answer right. For that matter, that work is itself the "right answer", which is why Hashem gave us a system in which Beis Hillel and Beis Shammai can disagree and still "eilu va'eilu divrei E-lokim chaim -- both these and those are the 'living' words of G-d". Because both worked the process.
That is the way we can fully realize our being "in the Image of the Divine", and to partner with G-d in the creative process. The latter being an idea explored at length in R' JB Soloveitchik's "Halakhic Man". Or as his grandfather, R' Chaim Brisker, put it, through the giving of the Oral Torah, the Jewish people were elevated into becoming the "parchment" upon which G-d's Word is written. The Torah becomes of us, instead of an externality to study.
There already are great answers, so I'll just add two more benefits to an oral law:
1) The written law (i.e. the Old Testament) was co-opted to form new religions. The oral law by definition will remain only among true scholars, who can be better trusted to keep it sacred and unique to Judaism.
2) Written texts are very limited in what they can teach. While they excel at holding facts and data, they struggle to convey methods of thinking and rules for dealing with principles. The benefit of oral instruction is that it serves better to convey these abstract ideas.
Let me present my personal, less orthodox explanation of the subject.
The reason for the Oral Torah not to be written is in fact because
Torah's is not about "keeping the ultimate truth", but about "searching for it". In other words, Hashem "does not care" about the results of the Halachah, He likes the process.
The ultimate proof would be the "Tanuro Shel Achnai" Machlokes between the Sages and R' Eliezer (B"M 59b). The Sages knew that the "absolute truth" is with R"E, but nevertheless decided Hashem likes their effort better. They ruled "לא בשמים היא" - the Sages' decisions are "better" (more valuable) for Hashem, that the Oral law traditionally received from Moses.
If the authenticity or the exactness of the Oral Law (unlike the Written Torah) was ever of a primary concern, I have no doubt we were explicitly obligated to write it in stone, literally. The fact that the Jews spent 1500 years without written word clearly (for myself) indicates that either they all were geniuses, keeping data of a whole library in their heads (which does not seem plausible) or did not care about its validity.