That would overwrite from the beginning rather than append. Unless the file is small enough to read into an array, unshift the new first line in, do the same zero-seek and then print it back in this overwrite mode, a much more complex solution would be required using read aheads, rewriting the previous buffer and iterating through the whole file.