The issue is simple to fix. There is one prerequisit to write a file in PL/SQL, a diractory.
create or replace directory dir_temp as ‘c:\temp’;
grant read, write on directory dir_temp to public;
When the diractory is used like here:
P_DIR IN VARCHAR2 DEFAULT ‘DIR_TEMP’
The variable value has to be UPPER case!