In Biblical history, Egypt was both refuge and trap--often at the same time.
Abram was willing to listen when God told him to go to Canaan, but seems to have decided all by himself to go to Egypt during a famine. It seemed like a no-brainer..and it's not easy to really believe God can take care of you better than you can. I have learned is that God doesn't prevent all the possible disasters that might happen to you, but He does get you through it. One thing that did come out of this soap opera situation was that we read that Pharoah gave them, among other things, "male and female servants". There is an Islamic tradition that Hagar was a king's daughter and was originally intended as a wife for Abram before he admitted to being married. That whole triangular situation was probably more complex than it appears.
On the other hand, God did set the situation that got Joseph and then his family to Egypt--and then eventually out. Egypt was actively trading and politicking in that whole area, and by the time of the Assyrian expansion in the 7th Century BC there was a Jewish community on Elephantine Island in the Nile near Aswan, complete with military outpost and operating Temple, the only other temple to perform sacrifices. Archeological research has shown remnants of pagan practices there as well-which illustrates one of the problems--Egypt was both powerful and pagan. We find in Isaiah 30 and 31, written when the Assyrians were besieging Jerusalem: "Woe to those who go down to Egypt for help, who rely on horses, who trust in the multitude of their chariots, and in the great strength of their horsemen, but do not look to the Holy One of Israel or seek help from the Lord. ..But the Egyptians are mere mortals and not God; their horses are flesh and not spirit. When the Lord stretches out his hand, those who help will stumble, those who are helped will fall, all will perish together."
A generation later, King Josiah of Judah marched into battle between Egypt and the waning remnants of Assyria, despite messages from Necho, the king of Egypt, that God had told him that Josiah should stay out of the way. Josiah (who was one of the "good kings" of Judah) went out to battle anyway and was killed. At the time of the Babylonian conquest in 586BC, Jeremiah was told that the people who were not taken to Babylon should stay in Judah, work the land and God would take care of them and they could rebuild. (Jeremiah 42-44). However, the people didn't listen, led everyone to Egypt, by force if necessary, and continued the idol worhip that had gotten them into trouble back home.
During the period of Alexander the Great and his successors, a large community of Jewish refugees and captives from Ptolemy's capture of Judea grew up in Egypt, mostly in Alexandria. This became a very Hellenized, Greek-speaking culture, and it was in Alexandria that the Hebrew Scriptures were translated into the Greek version that is quoted in the New Testament. It is not surprising that when Joseph was warned that Herod was looking to kill the baby Jesus that Egypt was their refuge. It is possible that they had relatives or connections there. Alexandria also had one of the first major Christian churches, founded by St Mark. The Egyptian church became a large and vibrant community, but after the Muslim conquest of the 7th century, political and economic pressures made it a minority by the 12th century. The Coptic Orthodox church in Egypt today lives under under pressure and persecution by the Muslim majority, has seen major emigration, and is now estimated at about 10% of the population. What had been a major Jewish subculture in Egypt was pretty well pushed out in this century, and is now estimated at less than 40, mostly elderly women.
Egypt and Israel's current uneasy coexistance is just the latest chapter in a long and entangled history. There have been times that God used Egypt for His people's good, and many times Egypt was the exemplar of where people who should have known better turned their backs on God's words and thought they could solve their own problems. It is today a place on the front lines of struggles between people who all claim to worship the same God.