At least on the RedHat machine I have here, processes are actually sent SIGTERM twice. Once from shutdown, and once from init. Init sends this signal to any process not belonging in the new runlevel it's switching to (in the case of a halt or reboot, 0 or 6 respectively), and your daemon should be included in this (if it's still in the original process group given to it's ancestor by init, or if it has become a child of init).
Here's the clincher however: 5 seconds after this SIGTERM, init follows this up with a SIGKILL, which is not trappable. In your script, as Tomte has suggested, the actual action to be taken upon receipt of the signal is deferred until later (the handler just sets a flag variable). It might be the case that your script simply does not get to reading the flag variable before those 5 seconds are up. Try adding something in sub handler that logs receipt of the signal, so you can verify whether you actually receive it and are just too late to act upon it.
CU
Robartes-