You also need to connect the handler should quit after last window closed of the Application and File’s Owner to your main script file (or the one that has the code you mentionned) for it to work.
Connections are often the source of such bugs, i.e. when nothing happens where you expected something to. You should check there first before anything else.
Browser: Safari 531.9
Operating System: Mac OS X (10.6)
Additionally I recommend to first make the connections in Interface Builder.
If the connection is successful, the code of the handler will be inserted automatically in the script.