file_save_data fails in CLI
Stupid bug. The script would change the current directory. Drupal code, it seems, assumes that it will be running from Drupal root, so the file attachment paths are relative internally. chdir(DRUPAL_ROOT) before calling file_save_data fixed it.