Updated debug-to-file code