Probably it's because the first two lines are running at the same time, so AJAX haven't got the time to request the file yet.
Instead of using "on start of layout" try using "on AJAX finished" or something like this, I'm sure it had an option like that.