Minor improvements to CardGenerator and the corresponding unit test

Make sure that the file gets closed when writing a card to/reading a
card from disk. Also add a unit test for the error condition when trying
to import a card from a non-existent file.