This is an ideal solution for anyone working on ROS. So I divided the solution into two parts - one, storing it as ROS bag files (a handy tool for storing any kind of data from ros topics) and two, writing rosbag files to pcd files. This is really simple now.
(References: http://wiki.ros.org/Bags)
A) STORING DATA in BAG files. (ROS file type)
First store the data (any kind of data can be stored) as ROSBAG. ROSBAG just records data from topics.
1.To start using kinect, open a terminal and run
$roslaunch kinect2_bridge kinect2_bridge.launch publish_tf:=true
This will let ROS system start getting data from kinect. You should see the system starts and stops with "waiting for clients to connect".
2.To view the point cloud, open a new terminal. Run
$ rosrun kinect2_viewer kinect2_viewer sd cloud
And you will see a new window pop up with a point cloud view. Here's link explaining the parameters for kinect2_viewer function: https://github.com/code-iai/iai_kinect2/tree/master/kinect2_viewer
3.To record the data,in a new terminal run
$ rosbag record -O pcl_sample1.bag -a
Here "-a" means you will subscribe to all available ros topics and record data from them. After you think the data is enough you can stop it by ctrl-C. The data will be stored in a .bag file, here name.bag. More settings can be found here:http://wiki.ros.org/rosbag/Commandline#record
Now unplug kinect. The bag file has data of all the topics which were run by launching kinect2_bridge. Now you can use the data from topics as if kinect was actually plugged in.
4.To play back the data, you need to stop the program in the first terminal (the launch file). Then you run
$ roscore
This will start a ROS server. Then in the other terminal, run
Play the bag file:
$ rosbag play pcl_sample1.bag
This will let ROS system play back the data you just recorded as if the device is still working. You can then use kinect2_viewer to see the data i.e.:
Run any commands Kinect was actually plugged in.
$ rosrun kinect2_viewer kinect2_viewer sd cloud
Note: If you want to record specific topics, visit http://wiki.ros.org/Bags.
B) CONVERTING BAG TO PCD Files: (It is just one command now.)
Writing appropriate topics to respective folders:
rosrun pcl_ros bag_to_pcd pcl_sample1.bag /kinect2/sd/image_color_rect src/
rosrun pcl_ros bag_to_pcd pcl_sample1.bag /kinect2/sd/image_depth_rect src/PCD\ Files/