You can login just fine. A 3DS console can have any number of NNID's linked to it, but only one can be active at a time. To switch between the active one, the system must be formatted. What you described is the way to go about it. You do not however, need to format before transfer, as transferring will format the device.
Formatting does not unlink the NNID though; Were it unlinked, it'd be usable on ANY console, not just that one. It'll still remain linked on that console; hence why you can login on the same NNID after format.