Educating a population for exactly the right number of jobs needed takes decades and a crystal ball. It requires the ability to foresee changes in the workforce brought about by technology, economic and other factors. It's not so long ago that hundreds of thousands of people were employed in the branches of high street banks, for example. It allows a country to be far more flexible and innovative if a workforce is mobile, which means making use of immigrants.
Not only that, but as a population becomes more educated, there will always be jobs which people don't want to and won't do. People who have tramped halfway round the world in dangerous circumstances don't want to do them either, but they accept them to earn money. Most of them will be aspirational (that's why they risked so much) and will study to improve their job opportunities. They need a constant supply of people following them on the same path.
Moreover, it's not always a question of people preferring benefits to low paid work. There are many towns like mine which have an extremely low unemployment rate - at the same time restaurants, shops and care and cleaning organisations can't find people because there aren't any. Goodness knows what would happen if all the foreigners in the workforce disappeared.