This is a hard question to answer simply because opinions will vary depending on religious philosophy but I'll attempt to explain the philosophy behind it without getting too specific although I may do some guess work from what I do know about Catholicism since that is the religion that is portrayed in the film.
The idea behind being able to cast out a demon comes from having authority over it. God created all the spirits including those which were cast out and became evil spirits serving Satan. These demons try to trick men by telling lies, temptations, and they also can gain power over them at times by possessing their bodies. Not everyone is susceptible to possession but I won't get into that. The key thing to understand is that because they are creations of God, ultimately these evil spirits must answer to the authority of God.
If someone with the authority of God asks a demon its name using that authority, the demon must give it. That authority is also what gives a person the ability to cast the demon out. From the best of my understanding, the Catholic Church teaches that this authority comes chiefly through Faith and Study of the Scriptures.
In the movie, both the Warren's live by these principles of authority and that is why they could be sure that the name given was the true name of the demon which they could then use to cast it out.
For a reference, here is an interview with a Catholic priest about exorcisms. In this snippet he points out that they always start by asking for the demon's name and that the demon answers.
"Demons are wary of talking and must be forced to speak. When demons are voluntarily chatty it's a trick to distract the exorcist. We must never ask useless questions out of curiosity. We but must interrogate with care. We always begin by asking for the demon's name."
"And does he answer?" I ask. Father Amorth nods. "Yes, through the patient, but in a strange, unnatural voice. If it is the Devil himself, he says 'I am Satan, or Lucifer, or Beelzebub. We ask if he is alone or if there are others with him. Usually there are two or five, 20 or 30. We must quantify the number. We ask when and how they entered that particular body. We find out whether their presence is due to a spell and the specifics of that spell.