Working version of txt writer