The evolution of the baryon fraction in haloes as a cause of scatter in the galaxy stellar mass in the EAGLE simulation