It's actually just a matter of air pressure. If this little hole on the barrel wasn't there, the pressure inside the pen would be weaker and the ink would flow less and less. The hole is meant to create the same level of pressure inside and outside the pen.
Discover our latest podcast
The hole in the cap
As for the hole in the cap, it appeared in 1990 for security reasons! Many children had choked on the pen cap. Pierced pen caps therefore became mandatory in 1991. This hole is meant to let the air into the throat of a potential victim, in the event that they swallow the cap, in order to limit the risk of suffocation.