For some unknown reason that script attached under doesn't change target before target is destroyed.
Edit: New scripts, version 2 seems to work but is workaround.
That would seem to be expected behaviour, no? If it doesn't change when new units move closer, or the target moves away, that's going to need a closer look.
You might want to only check targets when about to fire, to lower lag when the player has built a lot of units.