There is no grammatical reason why the answer you gave should not be a valid one. The only reason the official answer is better is because of the meaning. This is why tests are often hard; you're forced to choose among several valid options and decide which is the most likely one.
The example sets up a contrast; the uncle used to live in Alexandria, and now he lives in Cairo. Present perfect is often used for actions that are "ongoing." "I've been a grocer for 20 years" implies that I still am one. So it would be an odd choice for this example. But if the example were just "My uncle has lived in Alexandria for 20 years"—and he still does—then there's no problem. Or if he now has two houses:
"My uncle lived in Alexandria for 20 years. Now, he also lives in Cairo."
There are even other tenses that would be grammatical but unlikely. How about the future tense!
"My uncle will live in Alexandria for 20 years. Now, he lives in Cairo."
This time there isn't even a conflict in the meaning. This is just an unlikely thing to say because we don't normally plan how long we live in a city. But the same tenses and construction might be fine for a different situation:
"Soon I will study for 20 minutes. But for now, I eat."