You almost certainly ended line 1121 incorrectly somehow, and the Python interpreter expected the incomplete expression to be continued onto line 1122. When it could not parse 1122 as a continuation of 1121, that is what caused the syntax error, rather than anything particularly wrong with line 1122 itself.
Also, it is not true that "f.write is only good for xyz number of lines"; to demonstrate I wrote the following test-program generator:
import random
import string
GENFILE = "testwrite.py"
HEADER = "with open('testout.txt', 'a') as f:\n"
BODY = " f.write(\"{}\")\n"
BODY_N = 100000
def randstr(n = 1, ch=string.lowercase):
return ''.join(random.choice(ch) for i in xrange(n))
def main():
with open(GENFILE, 'w') as outf:
outf.write(HEADER)
for i in xrange(BODY_N):
outf.write(BODY.format(randstr(10)))
if __name__=="__main__":
main()
which created a program that looks like
with open('testout.txt', 'a') as f:
f.write("ugakajlxkv")
f.write("tskhodwgwr")
f.write("vrqcrnxhcz")
f.write("yijyqfyjug")
f.write("gbsthkkkdc")
f.write("vmupgtotoe")
# ... 99,994 more lines
which runs quite happily.