The current dupe scan was implemented to detect and delete items with the same Item ID Tag within a single game server. Items are given an ID Tag when they are generated. Item ID Tags are NOT the same as the Item IDs you would see when monitoring packets. ID Tags are never removed or changed, but only certain items have the Tags. Items spawned before patch 1.08 don't have ID Tags. When an item is inserted into the socket buffer of another item, its ID Tag becomes hidden from the scan, and only the item it is socketed in is detected.
The scan actually occurs each time a player leaves the game. All ID Tags within the personal buffers of the player that left are compared to those of everyone else in the game, on the ground, mercs, and I'm almost willing to say every buffer except sockets, but I can't confirm that. When IDs match, the item's "Duplicate?" flag is set to 1 and it is prepared for a state of oblivion. However, the item is not deleted from the server until you leave the game. In the 'olden days', if you duplicated an immune item, the dupes would be immune as well, but I believe this has changed now. Personalizing an item won't change the Tag. Something such as upgrading a rune may, however. I believe that would be the spawn of a new item and it would get a new tag. I'm pretty sure that this is already confirmed, but I have never played the realms seriously or long enough to keep track of much of anything since 1.09. Infact, much of this info is based on ... D2 years ago, so some of it may be changed now.
There IS a way to dodge the dupe scan temporarily even after your item has been flagged for being a duplicate. Reseting the deletion flag on your item is as easy as going into trade with someone, canceling, and leaving. The only thing is that after you go into trade with someone, you have to be the next person to leave, because what happens when a person leaves? Riiiight... all the other items get scanned again. This will temporarily save items in your cube, stash, and inventory/body. If you have a duped item on your body, you die, and then you leave the game even after opening the trade screen, the items saved on your dead body are still flagged and poof. You should do this every game if you are carrying any items you know/suspect to be dupes.
*This info was all from memory and based on the 1.09 era; I am sure there are errors.
There is no "duped" flag. And the only ID's ever seen by the client are only locally unique(i.e. within the specific game). The client is never aware of whether or not the server thinks it's items are duped until they get deleted.
You cannot make a dupe detector...and changing the ID of the item by entering/exiting trade will only temporarily perm the item. That is, until you join another game with another item that has the same server-side globally unique ID as yours(read: dupe).