Reading from a file:

with open('input.txt') as f:
    lines = f.read().splitlines()

Writing back out:

with open('output.txt', 'w') as f:
    for el in elems:
        f.write(el + '\n')