You can access Kirby’s API by including this at the top of the PHP file:
<?php
define('DS', DIRECTORY_SEPARATOR);
require($_SERVER["DOCUMENT_ROOT"] . DS . 'kirby' . DS . 'bootstrap.php');
$kirby = kirby();
$site = $kirby->site();
// do your thing here
Using this, you can keep the PHP file anywhere on the site - no need to clutter up your content and templates folder with something that is neither content nor a template.