I've just had to figure this out myself recently. The following feels like a bit of a hack, but it does work:
# NB. File::Spec isn't actually required,
# but it's a good cross-platform solution
my @module_dir_array = File::Spec->splitpath(__FILE__);
my $filename = File::Spec->catpath(@module_dir_array[0,1],'file.txt'),
It uses the __FILE__ literal which always points at the current filename (see perldoc perldata
). So you can put your file.txt file in the same directory as your module.pm and the module should always be able to find it.