Answer
The problem here is that the file will close before reading the data from the file.
Work Step by Step
Let's have a closer look at the code:
1while not end_of_file:
2$\hspace{4mm}$try:
3$\hspace{8mm}$print(pickle.load(infile), end = " ")
4$\hspace{4mm}$except EOFError:
5$\hspace{8mm}$end_of_file = True
6$\hspace{4mm}$finally:
7$\hspace{8mm}$infile.close() # Close the input file
Now if we look closely at the lines 6-7, we can see finally block is closing the file and this block is inside the while loop.
We know that finally block runs in every case, hence in the first iteration of the while block, the execution will reach at line 7 (since finally block always runs) and the file will get closed without reaching the EOF.