When you give your name and address to the polling station, they note the serial number of the ballot paper against your name and address and voter ID number, so it is possible to trace every single vote back to the voter who cast the vote.
In the case you suggest, they could simply notice that the same person has voted twice, find the voting slip that matches the record and mark it as void. This could be done by two separate people, one who knows the person's name, address and voter ID, and they could pass the serial number against that name and address to a second person who could find the ballot paper and remove it from the count of votes. That second person would never need to know any personally identifiable information, and therefore the secrecy of the vote is maintained.