Here's my guess for your first issue.....it gets executed at run-time - so it has not yet been executed when you hit the BEGIN block and launch in to your first test
That seems sensible. It also seems odd because I didn't write that code - it is part of the boilerplate produced by Module::Starter
I don't have an immediate guess for the second issue
At least I am not missing something obvious :)
$comp_pass2 should contain a floating point between -1 and +1. If the two stringified vectors are the same (like they are in the test), then the result should be +1. The compare method returns the Cosine Similarity of the two vectors derived from the test strings