It comes from a practice that was once common, at least in small towns, that a merchant would give you something extra as a thank you for your business. A baker might give you and extra roll when you bought a dozen, or an extra cookie. The store clerk might give an extra piece of candy. I heard it only occasionally as a boy, but almost never now.