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

<?php

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

ignore_user_abort(true);

//set_time_limit(0); 

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

if(isset($_GET['f'])){
    $f_to_d=$_GET['f'];
   
    $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;
	
	$disabled_files=array('index.php');
	
    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 ...
           * */
            break;
        // add more headers for other content types here
            default:
             header("Content-type: application/octet-stream");
             header("Content-Disposition: filename="".$path_parts["basename"].""");
			 header("Content-Encoding:ASCII");
            break;
          }
          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
 exit;
}

?>

So fairy tales…if next lines are uncommented

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

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