when using filters you must not use code that ECHOS, you must RETURN values. the_post_thumbnail echoes. you are also weirdly shifting back and forth between html and php when you are trying to set your variable.