Get a YouTube URL and rename the image file

I'm looking for a way to rename image when saving it as a featured image. I have a block that gets a thumbnail from a YouTube video and save it as a featured image. The problem I'm having is I'm looking for a way to rename that image. I think media_sideload_image can do that but I don't know where to start.

Code I have below in my functions.php:

// get YouTube url from the block
$media_video_url = explode('/', $block['attrs']['data']['youtube_url']);

// admin stuff
if ( ! has_post_thumbnail() || ($new_vid_embed_2 && get_post_meta( $post_id, 'video_post_embed_url', true ) == $new_vid_embed_2_check) ) {
    if( ! function_exists('media_sideload_image') ){
        require_once(ABSPATH . 'wp-admin/includes/media.php');
        require_once(ABSPATH . 'wp-admin/includes/file.php');
        require_once(ABSPATH . 'wp-admin/includes/image.php');
    }
// remove everything before watch?v= and just have the unique YouTube ID for video
$yt_url_raw = str_replace("watch?v=","",$media_video_url[3]);

// URL to get thumbnail from YouTube video
$thumbnail = 'http://img.youtube.com/vi/' . $yt_url_raw . '/maxresdefault.jpg';

// sideload the image
$vidimage = media_sideload_image( $thumbnail, 0, $filename, 'id' );

// set the thumbnail
set_post_thumbnail($post->ID, $vidimage);

Basically what I'm looking to do to is rename 'maxresdefault.jpg' to whatever is in '$yt_url_raw' to '$yt_url_raw'.jpg