Got output file writing working