write contents to file -> error ./output.json: bad file descriptor