Gem::FilePermissionError on "rails:freeze:gems" task

My understanding is that the “rails:freeze:gems” task copies the Rails
source into the application’s vendor directory. Which is why I find
the following error surprising and confusing, because the task should
not involve writing to system files or directories:

% rake rails:freeze:gems
(in /Users/tallen/apps/pnc)
Freezing to the gems for Rails 2.3.5
rm -rf vendor/rails
mkdir -p vendor/rails
cd vendor/rails
ERROR: While executing gem … (Gem::FilePermissionError)
You don’t have write permissions into the /opt/local/lib/ruby/gems/
1.8 directory.
rm -rf vendor/rails

Why does the task want to write to that directory? The output was
identical with the --trace option.