lines = ['line1', 'line2']
with open('filename.txt', 'w') as f:
f.writelines("%s
" % l for l in lines)
new_line = "This new line will be added.
"
with open("sample.txt", "a") as a_file:
a_file.write("
")
a_file.write(new_line)
fw.write('
'.join(line_list) + '
')