Can I use require() function in a template file?

You are seeing this error because you are requireing the file with a relative path. As @Mark Kapulun pointed out in the comments you should not use relative paths when requireing files. Instead you want to be explicit and use absolute paths.

Use get_template_directory() which returns the

Absolute path to the directory of the current theme (without the trailing slash)

In your template file the require statement will look like:

require( get_template_directory() . '/path/from/theme/root/to/file.php');

Or get_stylesheet_directory() if you are making a child theme. doc

Update:

As @Jack Johansson noted in his answer, you may also consider using require_once instead. This will protect you from errors generated by multiple inclusions of the file. See this answer for more details.