While this isn't a question that can be definitively answered, I've heard teaching that links these types of incidents to John 6:1-15, particularly verses 14-15 (NIV quoted here):
14 After the people saw the sign Jesus performed, they began to say,
“Surely this is the Prophet who is to come into the world.” 15 Jesus,
knowing that they intended to come and make him king by force,
withdrew again to a mountain by himself.
In terms of the interpretation of a number of Jesus' miracles, there are three key points that may be relevant to this example:
- Jesus knows that the people are expecting a Messiah who will free them from Roman occupation, not a Messiah who frees them from their sins. He will not allow the people to make him a political king, as he has come to be a sacrifice, not an earthly ruler (John 18:33-37).
- In several places in Scripture, Jesus indicates that his time has not yet come (confrontation with the Jewish leaders and the Romans in Jerusalem). For example, he tells his mother at Cana (John 2:4) as well as his disciples (John 7:6).
- Jesus' mission is to be obedient to the Father's will, not necessarily to gain the most publicity for his ministry.
In other words, the signs Jesus is performing to drive out demons are recorded so that we may know he is the Christ and that he has authority over evil spirits (also read Acts 16:16 for a similar story about Paul, as opposed to the sons of Sceva in Acts 19:11-20). That is why these events are written in Scripture.
However, for those present, Jesus is hiding his Messianic mission in the same way that he hides the secrets of his Kingdom in parables. This is partly because he is acting in obedience to his Father in terms of the timing of the public announcement of his son-ship, and also partly because God respects our freedom and will not force us to have faith in him. This is because a love relationship requires that each person in the relationship has the freedom to choose to love. Because Jesus allows us to reject him, we often see in Scripture that he does not transfigure himself in front of everyone, or do the kinds of signs people demand, or allow demons to proclaim him as Christ, as in many cases these events would almost surely compel people to believe.
So overall, I would say that Jesus acts this way because he doesn't want to compel us to believe, he wants us to freely choose to love and trust him (faith), and Gospels provide us with lots of good reasons to do just that.