To counter heretical movements like the Cathars, Bogumils and Waldensians, which started spreading rapidly at that time.
The Cathars were a particular problem for the church because they were creating their own territory and culture in southern France. The church felt extremely threatened by this.
The inquisition had both doctrinal and political roots. The church was not only interested in doctrinal purity, but political power as well, both secular and ecclesiastical (to stop Christendom from splintering; to maintain discipline in the ranks). This is particularly true for the 13th century, when the Catholic church was at the peak of its power (see Pope Innocent III).
While it would be wrong to attribute the emergence of the inquisition sole to political goals, it would also be wrong to say that these goals did not play a very important role. Both the "Black Legend" and revisionist white-washing are useless simplifications.
The Church (and the world as a whole) in the early 13th century was something very different from the present-day church. Many of the things that seem shocking to us were perfectly logical and natural to them in the context of their world view. You have to read up on European and Catholic history to understand the mentality of the the people who created the inquisition before you try to understand their motives.
Read more about the history of Church, about its decline in the second part of the 9th century, its absolute low point during the pornocracy (900-950), its rebirth under Hildebrand (Gregory VII), its absolute peak under Innocent III, its subsequent decline, the Avignon years, the Schism of the West, and the Council of Constance.
The history of the church is fascinating. I'm constantly dumbstruck by the fact that so few Catholics, even clergymen, know anything about it, or even seem to care.
By the way, I'm a 15 year old agnostic- if I could take the time and trouble to learn a little about church history, it's a travesty that Catholics themselves don't.