It leaves your save right away as soon as you generate the code! Since trades work completely offline with no server, removing it on export is what keeps it from being cloned, and locking the code to your friend's Trainer ID (plus one-time redeem tracking on their save) makes sure only they can claim it once. Just make sure to copy or send the code before closing the screen!