Stick with your FFL/FFU setup, all you need to do is keep track of the goods and bads as they enter and leave your FFL/FFU stack.
Create a DINT called, for example, Bads_In_Last_20
Each time a pallet is loaded, check if your stack is full (FFL control .DN bit on). After the first 20 pallets, it will always be on.
Assuming the .DN bit is on, perform your FFU to unload the pallet 20 pallets ago, and check the status of the pallet that was unloaded from the FFU. If it was a good pallet, do nothing. If it was a bad pallet, subtract one from Bads_In_Last_20.
Then, load your FFL. As you load it, if the entry is bad, add one to Bads_In_Last_20.
Instead of looping through your array each time and manually counting the bad pallets, just count them as they enter and leave - unless you manually clear or otherwise manipulate the contents of your FFL array, the only way bad pallet flags are getting in and out is with you counting them.