Whoops well spotted...unfortunately it still doesn't do anything, I close the window and that's all that happens, no data is stored.
I tried just a simple alert so I know it's definitely triggering the function:
<body bgcolor="#f2f2f2" onbeforeunload="alert("I am an alert box!");">
But even this isn't doing anything. I'm really stumped now.