I found the mechanism of the dupe. Doesn't have anything to do with saving and exiting.
1. Remove the item from a crate by clicking on the item stack.
2. Close the crate by pressing escape, not the X.
2.5 Repeat steps 1 and 2 to take items from the crate.
The items that you removed are in your inventory, and when you open the crate again, the stack of items is still in the crate.
3. Open the crate and deposit the items from your inventory into the crate by clicking on the items, as you would normally.
4. Close the crate by clicking the X.
The number of items in the stack in the crate persists.
Also, in the middle of testing the duping, an empty crate next to a full crate was somehow filled with the same items as the one next to it. I didn't touch those items, just opened and closed the crate and pressed escape to save and exit a few times.