I think the problem is that when the script comes to the first Telefoonkosten it recognises that it is different from the previous record and keeps it.
It resets the $Variable and moves to the next Telefoonkosten.
It checks it against the variable and finds it to be a duplicate, so it deletes it.
This automatically moves it on to the next record, and around the loop again.
It checks what is now the (original) 3rd Telefoonkosten, compares it, and deletes the record.
It now has no 'Next' record to go to, so the active record is back to being your original 1st Telefoonkosten .
It goes round the loop again and compares this record to the $Variable and finds it is the same, so it deletes it.
You will always lose the complete last group this way, I believe.
(BTW: I would include a Sort script step at the very start of your script, just to be safe.)
In the 'Else' section of the script you could check - before it is deleted - if the record you are on is the last record in the found set. (Although I'm sure there is a cleverer way than that.)
Since you are importing this data, you can also completely eliminate this scripted loop. (Though I believe sorbsbuster is dead on for why you are losing the last group).
Set a unique values, validate always validation rule on this field and records with duplicate values will be automatically excluded during import.
And the winner is!! "PhilModJunk" :)
"Set a unique values, validate always validation rule on this field and records with duplicate values will be automatically excluded during import."
Actually I found tthis solution about a half an hour after made the original post.
But I was still very interested to see an explanation or possible suggestions so that's why I waited a little bit before posting the solution.
Thanks for your contribution guys!