Think about the nature of the communication between the server computer running your script and your user's browser running on a computer which may be on a different continent across the far side of the world from your server. In particular, how is the user closing the browser window they are using going to affect the script running on a different machine. The internet uses a fair degree of magic to get its job done, but with a little thinking and investigation you can generally at least appreciate the nature of the magic and its limitations.
Perl is the programming world's equivalent of English