I'm reading the story of Joseph in Genesis 37-50. Joseph was not entirely undeserving of the hateful treatment he received from his brothers, but neither was he entirely deserving of it. His brothers were at fault, and so was his father, so openly playing favorites with his children.
Nevertheless, Joseph got tossed in a well, sold into slavery, bought by a big-wig, accused of rape, and "demoted" as a servant of the big-wig in his business (captain of the guard's prison). He desperately wanted out of this hole, but he spent his 30th birthday celebrating 13 years of affliction in the land of Egypt.
But something happened. God used Joseph to interpret dreams, and Joseph interpreted the dreams of Pharaoh himself. And Joseph not only interpreted the dreams, but he also made some suggestions that made Joseph's stock soar as far as Pharaoh was concerned.
A famine was coming, and Pharaoh put Joseph in charge. Joseph would store up grain during the good years for provisions during the bad. And ultimately, God would provide for his chosen people by means of Joseph the dreamer, the arrogant brat, the foolish boy, the hard worker, the faithful follower of God, the interpreter, the second in charge of all of Egypt.
Why did God do this?
God didn't need Joseph to provide for the family of Jacob. God didn't need to send a famine. God could have sent rain those seven years just like he had every other year of Jacob's long life. God could have not sent Joseph to Egypt and provided manna from heaven during the famine. Why did God send Joseph to Egypt? Why did he need a famine?
There are probably several good answers, but the one I'm mulling over seems to be best. God wanted everyone to know about God. Did Joseph know about God? Check. Did Jacob? Check. The brothers? Check. Egypt? Check. The world? Check. Everyone came to Egypt for bread, and you know they had to ask, "Why does Egypt have bread when no one else can grow a grain of wheat?"
I've heard people say that God provided salvation for his people by sending Joseph to Egypt, and that is true, but God was not required to send the famine. The reason God sent the famine, and in so doing saved his people, is for his own name's sake. God works throughout history to bring glory to his name throughout the universe.
Here's a New Testament example: the ultimate purpose of the church.
"To me, though I am the very least of all the saints, this grace was given, to preach to the Gentiles the unsearchable riches of Christ, and to bring to light for everyone what is the plan of the mystery hidden for ages in God who created all things, so that through the church the manifold wisdom of God might now be made known to the rulers and authorities in the heavenly places. This was according to the eternal purpose that he has realized in Christ Jesus our Lord, in whom we have boldness and access with confidence through our faith in him." -- Ephesians 3:8-12
God is in the business of glorifying his great name! What an idolater he would become if he did not seek the glory of that which is most glorious!
So, why a famine? For the glory of God.