Writing numbers to a file

The following program writes the first 4 powers of the numbers between 1 and 1000 in comma-separated fields to the file powers.txt:

f = open('powers.txt', 'w')
for i in range(1,1001):
    print(i, i**2, i**3, i**4, sep=', ', file=f)
f.close()

The file contents are:

1, 1, 1, 1
2, 4, 8, 16
3, 9, 27, 81
...
999, 998001, 997002999, 996005996001
1000, 1000000, 1000000000, 1000000000000