Any code outside of a definition is known as a top-level form; top-level forms are run after the entire source file has been parsed, regardless of their position in the file.
Also, top-level forms run in a new dynamic scope, so using set to store values is almost always wrong, since the values will be lost after the top-level form completes. To save values computed by a top-level form, either use set-global or define a new word with the value.