wp_redirect() does not work in custom template file

Redirects are performed by outputting HTTP headers, wp_redirect() just adds some bits on top of it for flexibility.

Headers are only ever meant to be used before any and all output to a page, since that is how HTTP response is structured.

Hypothetically it could work in template if you make sure it fires before any output. Practically it is a normal practice to deal with redirects on an appropriate hook, before any template/output is ever reached. The common hook to use is template_redirect.