Detect and optionally delete duplicates