Create folders in custom installation profile fails when usind drush site-install
I found a solution that works.

Drupal sets it's own constants, such as DRUPAL_ROOT which can be used instead of $_SERVER['DOCUMENT_ROOT'].

So, all I had to do was to change $site_root = $_SERVER['DOCUMENT_ROOT']; to $site_root = DRUPAL_ROOT;, for it to work correctly when installed via Drush.