At the beginning of your script you could close and then re-open both for shared update (which will fail if not redirected to a file), if that succeeds for both channels, print a one byte token to both channels, seek back to 0, reread and check for duplicates, flag the findings, seek both back to 0 again and then continue normally, which will overwrite the token from top. For whichever channel it fails on, open it again for normal output.