To answer this question, you'll need to know Ohm's Law: V=IR, as well as inductance which "stores" current or rather, resists changes in current.
What this means is that once a wire connection is made across the battery terminals current starts flowing through the wire. The current 'I' is equal to V/R, which is the battery voltage (9V) divided by the the resistance of the wire and battery. Now, remember the inductance of the system is going to try and maintain that current. When you disconnect the wire, even for fractions of sections, the inductance tries to hold 'I' constant. The act of breaking the connection makes 'R' go from very low to very high. Now if 'I' is constant and 'R' approaches infinity, then 'V' must also approaches infinity to balance the V=IR equation. That's how you get the voltage high enough to ionize gas and spark or burn a very small amount of remaining metal contact. Of course the voltage doesn't hit infinity because once it goes high enough to arc then current flows and discharges the inductance.
Earlier in this thread someone mentioned that when the connection is made for the first time only through a few small pieces of metal which causes all the current to flow through and burn it. That's actually incorrect since the few pieces of metal have a very high resistance, which won't allow enough current though anyways. It's only when the connection is broken that the system inductance forces the current higher than the resistance alone would allow.