Hi,
After you open the file, check if it is empty. If it is then write the headings.
Code:
data = open('test.data','a')
#Seek to end of file
data.seek(0,2)
if data.tell() == 0:
#File is empty, write heading
data.write('Column 1\tColumn 2\tColumn 3\n')
data.write('some data')