Unable to write to the file [closed]

I am reading individual lines from a file and replacing . in each line. In console.log() it is displaying the expected output but I am unable to write it back to the file.

r1.on('line', function(line) {
  line = line + line.replace(/./g,'_') + 'n';
  console.log(line);

  fs.writeFile("assertion", line, function(err) {
  if (err) {
    return console.log(err)
  }
})