File added programaticaly are not deleted when node is deleted
I think that file will be delete when you run cron. File can't delete because temporary file have time life. You can see code in file_cron.
function file_cron() {
  $age = \Drupal::config('system.file')-&gt;get('temporary_maximum_age');
  $file_storage = \Drupal::entityManager()-&gt;getStorage('file');

  // Only delete temporary files if older than $age. Note that automatic cleanup
  // is disabled if $age set to 0.
  if ($age) {
    $fids = Drupal::entityQuery('file')
      -&gt;condition('status', FILE_STATUS_PERMANENT, '&lt;&gt;')
      -&gt;condition('changed', REQUEST_TIME - $age, '&lt;')
      -&gt;range(0, 100)
      -&gt;execute();
    $files = $file_storage-&gt;loadMultiple($fids);
    foreach ($files as $file) {
      $references = \Drupal::service('file.usage')-&gt;listUsage($file);
      if (empty($references)) {
        if (file_exists($file-&gt;getFileUri())) {
          $file-&gt;delete();
        }
        else {
          \Drupal::logger('file system')-&gt;error('Could not delete temporary file &quot;%path&quot; during garbage collection', array('%path' =&gt; $file-&gt;getFileUri()));
        }
      }
      else {
        \Drupal::logger('file system')-&gt;info('Did not delete temporary file &quot;%path&quot; during garbage collection because it is in use by the following modules: %modules.', array('%path' =&gt; $file-&gt;getFileUri(), '%modules' =&gt; implode(', ', array_keys($references))));
      }
    }
  }
}

You can see line if($age) and line -&gt;condition('changed', REQUEST_TIME - $age, '&lt;'). It's logic when run cron delete file.
And you can go admin/config/media/file-system to see time life of temporary file. Default are 6 hours.