Great question - but like all great questions, it's not an easy one to answer. Yes, the Talmud does testify to the belief that there had once been multiple versions of the Pentateuch kept in the Temple (bear in mind that the Talmud is speaking of a time that somewhat predates its own composition), and the Talmud also mentions an uncertainty as regards the spelling of certain words. And yes, where the Talmud quotes biblical passages, the quotes are sometimes incorrect - and sometimes are of passages that don't even exist! That happens more rarely, but it does happen; see, for example, Berakhot 61a, which quotes a non-existent verse: "Elkanah walked after his wife".
So when did the text become standardised? Well, technically speaking, it never became 100% standardised, and differences (albeit minute) continue to exist between different texts. If you would like to see an example, consider the spelling of דכא / דכה in Deuteronomy 23:2. The two most ubiquitous Hebrew/English versions of the Pentateuch in print (the Artscroll and the JPS) both spell it differently to one another. That more differences don't exist is due to the work of the masoretes.
These were scholars who flourished in the early Middle Ages, who were responsible for counting letters and words (the Hebrew for scribe, sofer, also means "one who counts") and for developing lists of rare words and phrases. These lists came to be represented in an abbreviated form as marginal notes to what are termed masoretic bibles - the oldest of which, in its entirety and bound as a book, are the Aleppo Codex of the 10th century and the Leningrad Codex of the 11th. There are also very old masoretic manuscripts of Prophets, and of the Pentateuch as a stand-alone work.
Some of the paratextual elements of the Hebrew text (dots above letters, inverted nunim, raised letters, etc) also date back to this period, and in some cases almost certainly served as notations on the text made by masoretic scholars. They are still visible in handwritten Torah scrolls, such as are read liturgically in synagogues, despite these scrolls being stripped of the paratextual elements that people are most familiar with: the vowels and the accent marks (which function as a form of punctuation, amongst other things). The Talmud itself bears witness to some of these curious textual features, and provides homiletic interpretations of them.
The work that the masoretes did went a long way towards standardising the text, as did the work of those who added vowels and punctuation - two features that also serve to disambiguate tricky passages, to break the text up into verses and to otherwise resolve disputed reading traditions. But the biggest impact on the standardisation of the text was made by the development of movable type printing, which allowed for the copying and transmission of biblical texts without the sorts of mistakes so commonly made by scribes.
In my opinion, the best book on this subject is Emanuel Tov, Textual Criticism of the Hebrew Bible, but there are lots of others as well. I would recommend starting with that one, and if you want something more technical you can follow his bibliography.