Write lines

'w' overwrites; 'a' appends.

with open('out.txt', 'w') as f:
    f.write('line1\n')
    f.writelines(['a\n', 'b\n'])