title: Writing to file creates NUL in file
body: <p>when I write to a file (for a specfic write) a bunch of <code>NUL</code>'s appear in my text document. For example:</p>
  <p>main.py</p>
  <pre><code>    with open('database.txt', 'r+') as database:
          # Read database for all users
          allusers = database.read()
          allusers = str(allusers)
          # Split the users by splitter '&lt;&gt;'
          splitusers = allusers.split('&lt;&gt;')
          userplace = splitusers[userplace]
          userplace = str(userplace) + str('&lt;&gt;')
          print(userplace)
          allusers_as_list = allusers.split('&lt;&gt;')
          print(allusers_as_list)
          allusers_list_edited = [word for word in allusers_as_list if word not in userplace]
          print(allusers_list_edited)
          writetofile = ' '.join(allusers_list_edited)
          writetofile = str(writetofile) + str('&lt;&gt;')
          print(writetofile)
      with open('database.txt', 'w+') as database:
          database.truncate(0)
          database.write(writetofile)
      with open('usernum.txt', 'r+') as file:
          contents = file.read()
          list_contents = contents.split('\n')
          while (&quot;&quot; in list_contents):
              list_contents.remove(&quot;&quot;)
          del list_contents[userplace2]
          listToStr = '\n'.join([str(elem) for elem in list_contents])
          file.truncate(0)
          file.write(listToStr)
  </code></pre>
  <p>database.txt (yes I know I could've used an actual database and yes It's a mess but I've come too far now)</p>
  <pre><code>5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8,Justin 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08,test1&lt;&gt;9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08,test2&lt;&gt;9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08,test3&lt;&gt;9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08,test4&lt;&gt;
  </code></pre>
  <p>usernum.txt</p>
  <pre><code>Justin
  test1
  test2
  test3
  test4
  </code></pre>
  <p>When running (userplace=3) the output in usernum.txt is:
  <a href="https://i.stack.imgur.com/w0Xve.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w0Xve.png" alt="Output (NUl doesn't copy into here)" /></a></p>
  <p>Have I made a basic error or is there something else going on? I'd appreciate any help :). As always if this isn't reproducible and is not helpful on this site I will remove. Thanks</p>