Minor loss map export fix.

Refactored the risk loss map export so that export to a file-like
object works properly and doesn't break because it's expecting a
file path. (So for example, this fixes the export if you want to
export to a StringIO object instead of the filesystem.)

Note: This is needed for oq-engine-server, which doesn't export to the filesystem but rather, writes to StringIO objects and streams them via http.