But I think I've worked it out.. I changed from using strings to char's and now it seems to work fine.
Thats because std::string is far away from being POD, so I highly doubt that it can, in any form be serialized directly in a binary way. The problem here is that both className and scriptLocation are being read in from invalid data, e.g. pointer to memory locations that don't exist any more from the point where they were saved, and so when the loop goes out of scope, the temporary variable is destroyed, and the std::string destructor is trying to clean up the mess that was just constructed, which it can't. Thus the exception, and thus why it works until the progams exit if you make ent a global variable.