Ruby 1.9, 159159 156
This program generates files named "1", "2", "3" and so on.
b={}
I=1
eval T="$<.eachT="loop{|l|cc,d=ld=gets.split
d ?c==?*?b={}:d ?c==?!?b.delete(d):c==???puts(b[d]):b[c]=d :break}
open(I.to_s,?w){|f|f<<'b=%p
I=%d
eval T=%p'%[b,I+1,T]}"