Redirecting to a file works as expected but the list does not get printed if stdout is going to the terminal.