This example behaved badly when demonstrated in lecture in conjunction with the source txt file being deleted. The example has now been re-coded to be more robust and overall to behave better when the file is missing.
Note that this could have been done by replacing the 'r' in fopen with 'a+'. Not only would this save us from having to code in the if !file_exists structure, but removes the need to close the file and reopen it using the 'w' mode.