fix file descriptor leak when writing to megam training file

Currently if you train a lot of megam classifiers, you'll eventually run out of file handles!

This is because we weren't closing a file handle when we do a tempfile.mkstemp. This patch fixes that.