It is very unlikely that -rescan helped - all recent versions of bitcoin do rescanning automatically when necessary.
My guess is that you switched to the second wallet before the transaction from the first wallet made its way into the block chain. When switching back, it resubmitted, and the second wallet got it.
How does the recent client determine when rescanning is necessary?
It stores some hashes of blocks in the current tip of the block chain in the wallet file. On startup, the latest common ancestor of the block chain database and the wallet file is searched for, and a rescan starting at that point is performed.
I believe this was added in 0.3.21 or 0.3.22.