I figured it out! the problem is the path is not right! Thanks to this post : Alow users to delete uploaded images inside backend?
this function below helped :
function url_to_path_test($url){
$url=str_replace(rtrim(get_site_url(),"https://wordpress.stackexchange.com/")."https://wordpress.stackexchange.com/", ABSPATH, $url);
return $url;
}
So in my code if you change the remove previous image like this it will work :
//remove previous uploaded file
$author_profile_photo = get_author_profile_photo($user_id);
$url=str_replace(rtrim(get_site_url(),"https://wordpress.stackexchange.com/")."https://wordpress.stackexchange.com/", ABSPATH, $author_profile_photo["file"]);
@unlink($url);