In Ancient Judaism, preserving and accurately copying the scriptures was a task considered to be of the utmost importance. As such, an official Temple position dedicated to this task was created. Such a scribal position was not unique to Judaism; indeed, many ancient societies had trained professionals whose primary job was to maintain and copy religious records and scriptures.
Such copyists and maintainers of the religious records were regularly immersed in the text and thus quickly became experts in it. Thus, in Temple-era Judaism the term "Scribes" refers both to the copyists and to experts in the scriptures in general. In later Rabbinic writing, the Scribes are described as "teachers with authority" and elsewhere as "copyists and teachers" (jobs that taken on by Rabbisafter the Temple fell, with the specific scribal roles disappearing entirely by the Talmudic period). Such literature considers their teachings to have been authoritative and ascribes many legal interpretations to the Scribes. Scribes also functioned as councilors, philosophers, and sophists at times.
Historically, most of the scribes were probably priests or members of the priestly class. Ezra, for example, is described as a scribe (Ezra 7:6) and priest (Ezra 10:10). However, in the late Temple period, non-priests were added to the ranks as duties of the scribes increased. In the Maccabean period, the term "Scribe" became a title. Ben Sira describes a Scribe as a wise man with comprehensive knowledge.
Josephus does not speak of a specific "Scribes" group, but says that scribes were employed at all levels of government. As such, the Scribes of Jesus' day do not appear to have been a distinct social group, but more akin to bureaucrats. That is, experts on the Law and Jewish life in general, not a distinct class of people. That said, the evidence suggests most lived in Jerusalem and were closely associated with the Temple priests. These Scribes likely help enforce Jewish law and pick Sanhedrin members.
This picture is consistent with the Gospel accounts. Mark describes the Scribes as high officials and advisors of the priests. Matthew portrays them as learned leaders of the people. Luke shows them as leaders and protectors of Judaism associating with the Pharisees and Chief Priest. Collectively the accounts show people who did not necessarily have official power, but yielded considered authority due to the people's respect for their knowledge.
Source: Allen Ross, "The Scribes" (2006), hosted at Bible.org