I've tried out the file and it works for a spell with cast time, but the script doesn't seem to work with an instant cast DoT spell (Moonfire) with condition 'target buff' for my dot. The bot will cast the Dot on the enemy, switch target, then quickly switch back and refresh the Dot on the original target.
Also, I tried making a macro for target nearest enemy as Networkz suggested so the bot uses the macro every 2 seconds and changes target but the bot doesn't seem to want to use the macro when in combat and if the bot changes target, it will just go straight back the enemy it was originally attacking.