Copy output data from a `for loop` to a text document in Python
<p>The code I'm working on opens a text file, prints the text file to python terminal then goes through the entire document copying all the words with the character 'e' and prints those to the terminal as well. It's then supposed to write those words to a separate text document.</p>

<pre><code>file = open("myfile.txt", 'r')
output = open("outputfile.txt", 'w')
file = file.read()
print(file)
enter = input('Press enter to see all words with e.')
for words in file.split(' '):
    if 'e' in words:
        print(words)
        output.write(words)

output.close()
</code></pre>

<p>The program runs fine until it has to copy the text from the loop to <code>outputfile.txt</code>. </p>

<p>The result should like this in the output file:</p>

<pre><code>The
extra
three.
document.
...
</code></pre>

<p>But instead the output file looks like:</p>

<pre><code>Thisextrathree.The
...
</code></pre>

<p>It keeps some words that didn't appear in the loop and presses everything together. I'm not sure what the problem is.</p>