Check if plugin is being disabled

Sure, there are activation and deactivation hooks. See: https://developer.wordpress.org/plugins/plugin-basics/activation-deactivation-hooks/

<?php
register_deactivation_hook( __FILE__, 'wpse_deactivate_myplugin' );

function wpse_deactivate_myplugin() {
// Delete the file and do any other cleanup needed here.
}