There are several reasons why this might be happening. One possible cause is that you are overwriting the file each time the loop runs. Another reason could be that you are not properly closing the file after each write operation. This can lead to data being lost or overwritten.