According to the doc about Run tests by node ids
since you have all node ids in foo.txt, just run
pytest `cat foo.txt | tr '\n' ' '`
this is same with below command (with file content in the question)
pytest tests_directory/foo.py::test_001 tests_directory/bar.py::test_some_other_test