Under Roman rule, Egypt was not only the granary of the Empire, but also a major source of revenue through land and trade tax. But as the Middle Ages developed, the newly developed urban centers of Western Europe, like Flanders and Northern Italy, seemed to rely more on grain from the southern Baltic coast and the Crimea and its surroundings, respectively.
Even after European powers gained undisputable military superiority by the middle of the modern era they didn't seem to covet Egypt as source of food, but trade (e.g. Napoleon's Egyptian campaign). As a matter of fact, as I understand it, the land of the Nile started to focus more and more on cash crops like cotton instead of grain.
So why did Egypt lose its preeminence as major exporter of grain? Were other regions productive enough to meet Europe's market demands, even though they had a shorter growing season (but perhaps very fertile soil)? Was it because Europe's population boomed throughout this period, and so the arable land of Egypt became relatively small?
I answered a similar question a while back, but in short, you're on the right track with your last sentence -- although it wasn't the population of Europe that expanded, it was the population of Egypt that either doubled or tripled (the population in 1800 is only an estimate) over the 19th century which, as you rightly guess, increased the demand for grain consumption locally and left less for export.
Under the Ottomans (1517 onward), Egypt was a large exporter of grain, but their primary market was other parts of the Ottoman empire rather than Europe. The Ottomans had a very complex requisitioning system for grain and distributing it to less agriculturally productive parts of the Empire. Europe, meanwhile, benefitted from the introduction of new and hardier varieties that they could grow at home (better able to withstand cold, etc.), as well as the ability to import grain from the Americas.
So, by 1798 when Napoleon arrived, the Egyptian economy wasn't very Europe oriented. The Egyptians in the 19th century made a huge push to expand the amount of agricultural land by draining marshlands in the Delta, in particular, but the government was looking to produce cash crops for export to boost national revenue. The initial investment was in sugar and tobacco, but then cotton took over in late century when the American Civil War and the union blockade took the cotton-producing states of the Confederacy offline and worldwide cotton prices soared.
Egypt still produced some grain for export (it was considered to be high quality, and it would be sold for a profit, with cheaper grain brought from India for domestic consumption) as late as the early 20th century, but by that point Europe had lots of other sources it could tap into for supply, so it wasn't as important a source as it once was.