I believe it was for two reasons. First, to show that you should never doubt and underestimate God. Second, to show all of Egypt that the great pharaoh of Egypt could make mistakes like anyone else, and that he was also a mortal, a human like everyone else. The first five plagues were warning before the real trouble came. No one forces, preordains, or impels a person to act.
People do as they wish to do.
Each is absolutely free to perform any deed, be it bad or good. This is important to us as a Jewish people because it tells us to have faith in God and that God will always protect us. Pharaoh had the choice to make a good or bad decision, and he chose bad, therefore, God wanted him to know the consequence. Moses had to trust that God would fulfill his promise. He kept going back to Pharaoh even though pharaoh kept rejecting him.