I found another lines exports the result out of query_to_csv and the problem solved.
function exportCSV(){
//$this->load->helper('csv');
            $balance=$this->m->excel($allocation,$category);
            //query_to_csv($balance, TRUE, 'Balance.csv');
            //////
            //Step 3: Execute the query to export data from MySQL table
            $data = $balance->result_array();  //Fetch result in array format.
//Step 4: Write data into CSV file and save it on server.
            $fileName = 'Balance-'.date('Y-m-d').'.csv'; //Set file name with current date.
            header("Content-Description: File Transfer");   //Set header for download file.
            header("Content-Disposition: attachment; filename=$fileName");
            header("Content-Type: application/csv; "); //Set content type for download file.
            $file = fopen('php://output', 'w'); //Open file pointer in write mode.
            fputs($file, "\xEF\xBB\xBF"); //Encode UTF-8 BOM in file pointer.
            fputs($file, "Allocation,Category,Item Name,SN,Warehouse,QTY,AVG,Amount,\r\n"); //Encode UTF-8 BOM in file pointer.
            foreach ($data as $row) {   //Write each row of data into CSV file.
                fputcsv($file, $row);
            }
            fclose($file); //Close file pointer after writing all data into CSV file.
            
}