Abnormal behaviour of PHP codes attached to Drupal

I used next php codes to download files . There installed drupal, and i have some installed custom or modified modules. PHP script (Downloaded from inet and modified a bit) containing next codes located at drupal installation root directory


//define('DRUPAL_ROOT', getcwd());
//include_once DRUPAL_ROOT . '/includes/bootstrap.inc';



$path = getcwd() . "/files_to_download/private/"; // change the path to fit your websites document structure

    $dl_file = preg_replace("([^wsd-_~,;:[](].]|[.]{2,})", '', $f_to_d); // simple file name validation
    $dl_file = filter_var($dl_file, FILTER_SANITIZE_URL); // Remove (more) invalid characters
    $fullPath = $path.$dl_file;
    if (!in_array($dl_file, $disabled_files)){
	 if ($fd = fopen ($fullPath, "rb")) {
       $fsize = filesize($fullPath);
       $path_parts = pathinfo($fullPath);
       $ext = strtolower($path_parts["extension"]);   
           switch ($ext) {
             case "pdf":
           * CASE BLA BLAS ...
           * */
        // add more headers for other content types here
             header("Content-type: application/octet-stream");
             header("Content-Disposition: filename="".$path_parts["basename"].""");
          header("Content-length: $fsize");
          header("Cache-control: private"); //use this to open files directly
          while(!feof($fd)) {
            $buffer = fread($fd, 2048);
            echo $buffer;
			//echo "filesize is ".$fsize;
       fclose ($fd);
    } else {echo '<h1>'.'Just 404'.'</h1>';}//file not exists
  } else {echo '<h1>404 +</h1>';} // file name is forbidden


So fairy tales…if next lines are uncommented

 //define('DRUPAL_ROOT', getcwd());
//include_once DRUPAL_ROOT . '/includes/bootstrap.inc';

i get below shown 4 more bytes at the beginning of the downloaded files :
EF,BB,BF and 0A (even if original file is empy) Ithink this is UTF-8 encoding flag
Drupal version is 7.50
How to resolve this problem ?

Drupal version: 

Source: https://www.drupal.org/taxonomy/term/4/feed