system: Use RAII in System.dumpHeap and logging for file pointer
Avoids accessing the file handle after it is destructed. Avoids duplicating the js::DumpHeap() call and will be used later in System.dumpMemoryInfo() as well, in #292 (closed).
Closes: #410 (closed)