Unique ID beneficiary no sometimes getting duplicates

In case it helps, this is my coding... any advice is very gratefully recieved as Im at a real loss here!

thanks Nicola