open (MYFILE, '>>data.txt'). Open data.txt, save the source data and add data from the end.open (MYFILE, '>data.txt'). Open data.txt, delete everything from the inside and write the data from the very beginning.
From perldoc -f open:
If MODE '<'or nothing, the file is opened for input. If MODE '>', the file is trimmed and opened for output, if necessary it is created. If MODE '>>', the file is opened for addition, and if necessary it is created.
This is due to the use of the shell,
cmd < file.txtto copy the file to stdin,cmd > file.txt to write stdout to a file andcmd >> file.txt, stdout .