Writing to file dosen't work so good