Because it was better as second class citizens in those countries, with less pogroms and less hardships- compared to what Jews faced in Europe. And your argument holds no water because the inverse would be argued too- why did Jews stay in Europe if they were persecuted and killed over 2000 years?
If you were actually interested, I could list all the blood libel and pogroms in North Africa that occurred. Enough of this whitewashing of history. I mean, when Jews were allowed to wear shoes by the Sultan of Morocco- so many Jews were attacked in the resulting riots by local Muslims, that Jews begged that decision be reversed.