Demons are often seen as agents of the Devil set out to test the faith of people. However, given that demons themselves are proof of the Devil's existence and therefore the existence of Hell, one has to question the effect any "test of faith" caused by demons appearing. The fact that demons also seem to appear allmost exclusively before people who allready believe in their existence would seem to reduce their efficiency in this regard even further.
Demons are supposedly able to enter and take control of a human or animal in a process called possession. The Catholic Church uses the ritual of exorcism to expel demons from the victims they possess. Many Protestant denominations also have rituals or rites to cast out demons, though most of these are considerably less formal or complicated than the Catholic version of the same procedure.
The reason god would create angels with the ability to invade human bodies and control them is not explained in the Bible.