Genericized the debug out string/file handling for reuse

See title