Save XML string parameter received as parameter to a stored procedure in file

I am trying to save the xml string parameter received as a parameter to stored procedure in SQL server management studio 2012 in a file

When I try
DECLARE @cmd sysname, @var sysname;
SET @var = 'dir/p';
SET @cmd = @var + ' > dir_out.txt';
EXEC master..xp_cmdshell @cmd;

I get output having error as:
Access is denied

where is it trying to create a file?
I am running my code on test box connected to the server in ssms
please let me know what I should check if I am not having access to create and write to a file

dir/p
/p Pauses after each screenful of information.

  1. why are you doing what you posted?
  2. how are you un-pausing the /p
  3. where is the xml you talk about
  4. where is the stored procedure you talk about